Skip to content

names of anonymous functions generated as annotation arguments are not unique #15054

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

Closed
bertlebee opened this issue Apr 28, 2022 · 3 comments · Fixed by #16699
Closed

names of anonymous functions generated as annotation arguments are not unique #15054

bertlebee opened this issue Apr 28, 2022 · 3 comments · Fixed by #16699

Comments

@bertlebee
Copy link

Compiler version

3.1.1

Minimized code

https://scastie.scala-lang.org/JyCTJBMCRIKW73xNmAuaLA

import scala.annotation.Annotation

class AnAnnotation(function: Int => String) extends Annotation

@AnAnnotation(_.toString)
val a = 1
@AnAnnotation(_.toString.length.toString)
val b = 2

Output

Double definition:
def $anonfun(_$2: Int): String in object Playground at line 9 and
def $anonfun(_$1: Int): String in object Playground at line 7

Expectation

generated anonymous functions should have unique names

@bertlebee bertlebee added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 28, 2022
@bertlebee
Copy link
Author

similar issue for annotations on function arguments
https://scastie.scala-lang.org/9pEHR8DqSr6MbGci5ONv0w
and
https://scastie.scala-lang.org/gFlKy6QATEqpQcNyvs7R4w

@mbovel mbovel added area:annotations and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 28, 2022
@szymon-rd szymon-rd self-assigned this May 19, 2022
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2023
The previous logic tried but had holes. A local context was
established in `typedStats#localCtx` but that context was not
found in annotations that were typechecked in the completer
of the definition they decorated.

We are now more through and always allocate a localDummy as
new owner if the owner would otherwise we a class. This means
that closures in annotation arguments will have a term as owner,
and therefore will be allocated in distinct local scopes.

Fixes scala#15054

This broke two pickling tests where the source defined a local class
in an argument to an annotation of a toplevel class. Somehow a position
for these argument classes could not be found when unpickling. But
it does work for classes inside other classes or objects. I
changed the tests to nested classes, and kept one of the originals
in the pickling exclude list.
odersky added a commit to dotty-staging/dotty that referenced this issue Jan 14, 2023
The previous logic tried but had holes. A local context was
established in `typedStats#localCtx` but that context was not
found in annotations that were typechecked in the completer
of the definition they decorated.

We are now more through and always allocate a localDummy as
new owner if the owner would otherwise we a class. This means
that closures in annotation arguments will have a term as owner,
and therefore will be allocated in distinct local scopes.

Fixes scala#15054
@odersky
Copy link
Contributor

odersky commented Jan 14, 2023

Thanks for the report, and sorry it took so long to fix.

@bertlebee
Copy link
Author

Thanks for the fix :)

odersky added a commit that referenced this issue Jan 15, 2023
The previous logic tried but had holes. A local context was established
in `typedStats#localCtx` but that context was not found in annotations
that were typechecked in the completer of the definition they decorated.

We are now more thorough and always allocate a localDummy as new owner
if the owner would otherwise be a class. This means that closures in
annotation arguments will have a term as owner, and therefore will be
allocated in distinct local scopes.

Fixes #15054
little-inferno pushed a commit to little-inferno/dotty that referenced this issue Jan 25, 2023
The previous logic tried but had holes. A local context was
established in `typedStats#localCtx` but that context was not
found in annotations that were typechecked in the completer
of the definition they decorated.

We are now more through and always allocate a localDummy as
new owner if the owner would otherwise we a class. This means
that closures in annotation arguments will have a term as owner,
and therefore will be allocated in distinct local scopes.

Fixes scala#15054
@Kordyjan Kordyjan added this to the 3.3.0 milestone Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants