File tree 1 file changed +5
-6
lines changed
codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils
1 file changed +5
-6
lines changed Original file line number Diff line number Diff line change @@ -461,7 +461,6 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
461
461
Set <List <ShapeId >> pathsToShapes = new LinkedHashSet <>(
462
462
new LinkedHashSet <>()
463
463
);
464
- Set <ShapeId > visited = new HashSet <>();
465
464
466
465
// Breadth-first search via getDependencyShapeIds
467
466
final Queue <List <ShapeId >> toTraverse = new LinkedList <>(
@@ -470,16 +469,16 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
470
469
while (!toTraverse .isEmpty ()) {
471
470
final List <ShapeId > currentShapeIdWithPath = toTraverse .remove ();
472
471
473
- // to avoid cycles, only keep the first list with a given last element
474
- ShapeId last = currentShapeIdWithPath .get (
475
- currentShapeIdWithPath .size () - 1
476
- );
477
- if (visited .add (last ) && pathsToShapes .add (currentShapeIdWithPath )) {
472
+ if (pathsToShapes .add (currentShapeIdWithPath )) {
478
473
final Shape currentShape = model .expectShape (
479
474
currentShapeIdWithPath .get (currentShapeIdWithPath .size () - 1 )
480
475
);
481
476
final List <List <ShapeId >> dependencyShapeIdsWithPaths =
482
477
getDependencyShapeIds (currentShape )
478
+ // to avoid cycles, append only those dependencyShapeId which are not already in the path currentShapeIdWithPath
479
+ .filter (dependencyShapeId ->
480
+ !currentShapeIdWithPath .contains (dependencyShapeId )
481
+ )
483
482
.map (dependencyShapeId ->
484
483
Stream
485
484
.concat (
You can’t perform that action at this time.
0 commit comments