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

W-10548016: Fix traits not being applied to some operations of an extension #1403

Merged
merged 1 commit into from
May 10, 2022

Conversation

hghianni
Copy link
Contributor

…ension

@@ -170,7 +170,7 @@ class ExtendsResolutionStage(profile: ProfileName, val keepEditingInfo: Boolean,
val resolver = TraitTransformer()

// Iterate operations and resolve extends with inherited traits.
val traitList = endpoint.operations.flatMap { operation =>
val traitList = endpoint.operations.toList.flatMap { operation =>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this necessary?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WHAT... this is the only fix? Can you explain?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Streams are lazy. In this case when using flatMap for endpoint.operations, which is a Stream, the function is only computed for the first operation. This modifies the endPoint variable by applying the trait to the first operation. As the rest of the values of traitList are never used, the function is never computed for the rest of the operations and the trait is never applied to them. A way to solve is using a not lazy class like Lists.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using traitList.toStream.force also works as this will compute all values of the Stream which translates to function being computed for every operation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch!

@hghianni hghianni merged commit 72fb6e0 into develop May 10, 2022
@hghianni hghianni deleted the W-10548016 branch May 10, 2022 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants