Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Filter out synthetic traits before turning those into LoadOperations #1358

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}