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

Fix an issue with double forward reference #458

Merged
merged 1 commit into from
Jun 3, 2020
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 @@ -49,6 +49,7 @@
import software.amazon.smithy.model.validation.ValidatedResult;
import software.amazon.smithy.model.validation.ValidationEvent;
import software.amazon.smithy.model.validation.Validator;
import software.amazon.smithy.utils.ListUtils;
import software.amazon.smithy.utils.SmithyBuilder;

/**
Expand Down Expand Up @@ -436,7 +437,13 @@ public ValidatedResult<Model> onEnd() {

private void finalizeShapeTargets() {
// Run any finalizers used for things like forward reference resolution.
for (ForwardReferenceResolver resolver : forwardReferenceResolvers) {
// Do this through a copy to handle forward references that generate more
// forward references, like when a Prelude trait is applied to a shape that
// is defined in another file.
List<ForwardReferenceResolver> resolvers = ListUtils.copyOf(forwardReferenceResolvers);
forwardReferenceResolvers.clear();

for (ForwardReferenceResolver resolver : resolvers) {
// First, resolve to a shape in the current namespace if one exists.
if (!hasDefinedShape(resolver.expectedId)) {
// Next resolve to a prelude shape if one exists and is public.
Expand All @@ -450,7 +457,10 @@ private void finalizeShapeTargets() {
resolver.consumer.accept(resolver.expectedId);
}

forwardReferenceResolvers.clear();
// Resolve any new forward references created.
if (!forwardReferenceResolvers.isEmpty()) {
finalizeShapeTargets();
}
}

private void finalizePendingTraits() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ apply Foo @bar("hi")

// This applies smithy.example.b#baz to smithy.example#Foo
apply Foo @baz("hi")

// This applies smithy.api#deprecated to smithy.example#Foo
apply Foo @deprecated

// This applies smithy.api#sensitive to smithy.example#Foo
apply Foo @smithy.api#sensitive