Skip to content

Commit 3540436

Browse files
authored
fix(codegen): Allow multiple paths for a shape (#755)
1 parent 7a86bc8 commit 3540436

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

codegen/smithy-dafny-codegen/src/main/java/software/amazon/polymorph/utils/ModelUtils.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,6 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
461461
Set<List<ShapeId>> pathsToShapes = new LinkedHashSet<>(
462462
new LinkedHashSet<>()
463463
);
464-
Set<ShapeId> visited = new HashSet<>();
465464

466465
// Breadth-first search via getDependencyShapeIds
467466
final Queue<List<ShapeId>> toTraverse = new LinkedList<>(
@@ -470,16 +469,16 @@ public static Set<List<ShapeId>> findAllDependentShapesWithPaths(
470469
while (!toTraverse.isEmpty()) {
471470
final List<ShapeId> currentShapeIdWithPath = toTraverse.remove();
472471

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)) {
478473
final Shape currentShape = model.expectShape(
479474
currentShapeIdWithPath.get(currentShapeIdWithPath.size() - 1)
480475
);
481476
final List<List<ShapeId>> dependencyShapeIdsWithPaths =
482477
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+
)
483482
.map(dependencyShapeId ->
484483
Stream
485484
.concat(

0 commit comments

Comments
 (0)