Skip to content

Fix #7011: check possibly side-effecting transform #7016

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

Merged
merged 1 commit into from
Aug 10, 2019

Conversation

anatoliykmetyuk
Copy link
Contributor

@anatoliykmetyuk anatoliykmetyuk commented Aug 8, 2019

The transform function in question can be overridden with a version
that produces side effects. If that is the case, and if the superclass
transform function is called from the overridden transform function,
the overridden transform function might be executed twice with all its
side effects. This commit makes sure the transform function is not
called twice on the same input. An example where it can go wrong is:

https://github.com/lampepfl/dotty/blob/9a4b7d39a595dba3c0baf340b0bf911844fcae69/compiler/src/dotty/tools/dotc/typer/Typer.scala#L1080-L1094

Here, the transform function performs the side effect of entering a symbol
into scope. Furthermore, if the symbol already exists in scope, it emits
an error. Hence, if we call this function twice on the same argument,
we are guaranteed to get an error.

The transform function in question can be overridden with a version
that produces side effects. If that is the case, and if the superclass
transform function is called from the overridden transform function,
the overridden transform function might be executed twice with all its
side effects. This commit makes sure the transform function is not
called twice on the same input. An example where it can go wrong is:

https://github.com/lampepfl/dotty/blob/9a4b7d39a595dba3c0baf340b0bf911844fcae69/compiler/src/dotty/tools/dotc/typer/Typer.scala#L1080

Here, the transform function performs the side effect of entering a symbol
into scope. Furthermore, if the symbol already exists in scope, it emits
an error. Hence, if we call this function twice on the same argument,
we are guaranteed to get an error.
@anatoliykmetyuk anatoliykmetyuk changed the title Fix #7011: check possibly side-effecting transform Fix #7011: check possible side-effecting transform Aug 8, 2019
@anatoliykmetyuk anatoliykmetyuk changed the title Fix #7011: check possible side-effecting transform Fix #7011: check possibly side-effecting transform Aug 8, 2019
@nicolasstucki
Copy link
Contributor

@anatoliykmetyuk could you try to refactor the the code to make the diff smaller.

@anatoliykmetyuk
Copy link
Contributor Author

Basically if-else got replaced by the new context val at the beginning. What was inside the else block stayed the same.

@nicolasstucki
Copy link
Contributor

It is also to have a clean line history

@anatoliykmetyuk
Copy link
Contributor Author

If-else is gone now, hence indentation changed, hence the large diff

@anatoliykmetyuk
Copy link
Contributor Author

I don't think we can do anything about it

@nicolasstucki nicolasstucki merged commit ec51eb0 into scala:master Aug 10, 2019
@nicolasstucki nicolasstucki deleted the i7011 branch August 10, 2019 14:52
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