Skip to content

Commit

Permalink
Filter out synthetic traits before turning those into LoadOperations (#…
Browse files Browse the repository at this point in the history
…1358)

Synthetic traits should not be parsed again. That will cause a
failure, for instance, if we import a 1.0 model that has @enum
traits. If we try to reparse them this will fail with an error

Unable to resolve trait `smithy.synthetic#enum`
  • Loading branch information
sugmanue authored Aug 18, 2022
1 parent 7360b64 commit de20657
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,22 @@ void moveCreatedShapeToOperations(ShapeId shapeId, Consumer<LoadOperation> proce
operation.addModifier(new ApplyMixin(mixin));
}
builder.clearMixins();
// Remove traits from the shape and members and send them through the merging logic of loader.
shape.getIntroducedTraits().values()
.forEach(trait -> processor.accept(LoadOperation.ApplyTrait.from(shape.getId(), trait)));
// Remove traits from the shape and members and send them through the merging logic of loader
// filtering out the synthetic ones to avoid attempting to reparse them.
for (Trait trait : shape.getIntroducedTraits().values()) {
if (!trait.isSynthetic()) {
processor.accept(LoadOperation.ApplyTrait.from(shape.getId(), trait));
}
}
builder.clearTraits();
// Clear out member mixins and traits, and register the newly created builders.
for (MemberShape member : shape.members()) {
MemberShape.Builder memberBuilder = member.toBuilder();
member.getIntroducedTraits().values()
.forEach(trait -> processor.accept(LoadOperation.ApplyTrait.from(member.getId(), trait)));
for (Trait trait : member.getIntroducedTraits().values()) {
if (!trait.isSynthetic()) {
processor.accept(LoadOperation.ApplyTrait.from(member.getId(), trait));
}
}
memberBuilder.clearTraits().clearMixins();
operation.addMember(memberBuilder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -694,6 +694,24 @@ public void transientTraitsAreNotValidated() {
equalTo(originalId));
}

// Synthetic traits should not be parsed again. That will cause a
// failure, for instance, if we import a 1.0 model that has @enum
// traits. If we try to reparse them this will fail with an error
// Unable to resolve trait `smithy.synthetic#enum`
@Test
public void doesNotReParsesSyntheticTraits() {
Model model = Model.assembler()
.addImport(getClass().getResource("does-not-reparses-synthetic-traits.smithy"))
.assemble()
.unwrap();

Model.assembler()
.addModel(model)
.addUnparsedModel("foo.smithy", "namespace smithy.example\napply Foo @sensitive\n")
.assemble()
.unwrap();
}

@Test
public void resetDoesNotBarf() {
ModelAssembler assembler = new ModelAssembler();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
$version: "2.0"

namespace smithy.example

enum Foo {
HI
}

0 comments on commit de20657

Please sign in to comment.