-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Make annotation typechecking lazier #9302
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
Conversation
2abc534 to
db2b8f6
Compare
db2b8f6 to
a61e4fe
Compare
Now that `Typer.stabilize` ends up checking for `@uncheckedStable` annotations to support defs's as stable paths, new opportunities arise for cyclic errors. This PR reduces the likelihood of cycles by typechecking the only core of an annotation (_not_ the full application to the annotation arguments) to determine its type symbol. pos/unchecked-stable-cyclic-error.scala test case started to fail since scala#8338 with: ``` |-- object Test BYVALmode-EXPRmode (site: package <empty>) | |-- super APPSELmode-EXPRmode-POLYmode-QUALmode (silent: <init> in Test) | | |-- this EXPRmode (silent: <init> in Test) | | | \-> Test.type | | \-> Test.type | |-- def foo BYVALmode-EXPRmode (site: object Test) | | |-- attr EXPRmode (site: method foo in Test) | | | |-- Int TYPEmode (site: method attr in Test) | | | | \-> Int | | | |-- new anno APPSELmode-BYVALmode-EXPRmode-FUNmode-POLYmode (site: object Test) | | | | |-- new anno APPSELmode-EXPRmode-POLYmode-QUALmode (site: object Test) | | | | | |-- anno FUNmode-TYPEmode (site: object Test) | | | | | | \-> anno | | | | | \-> anno | | | | \-> (a: Any): anno | | | |-- (a: Any): anno : pt=anno EXPRmode (site: value <local Test> in Test) | | | | |-- foo : pt=Any BYVALmode-EXPRmode (site: value <local Test> in Test) | | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving method foo: while typing foo /Users/jz/code/scala/sandbox/test.scala:7: error: recursive method foo needs result type @anno(foo) def attr: Int = foo ^ | | | | \-> anno ``` Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of scala#8338). Backporting this fix makes that test start passing on 2.12.x.
a61e4fe to
9d9635d
Compare
|
@retronym see also #9144 where I had some reservations about building more stuff on top of |
|
@lrytz Test case added. |
c8d27c2 to
1d5c0ad
Compare
lrytz
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM otherwise. The main differences to #9144 are:
- Here we have
ExtraLazyAnnotationInfo extends LazyAnnotationInfo, where the other PR didQualifierTypedAnnotationInfo extends AnnotationInfo. This requires fewer overrides. - Here, typing the qualifier / annotation symbol is lazy, in the other PR it's done eagerly during Namer.
1d5c0ad to
2408bad
Compare
Now that `Typer.stabilize` ends up checking for `@uncheckedStable` annotations to support defs's as stable paths, new opportunities arise for cyclic errors. This PR reduces the likelihood of cycles by typechecking the only core of an annotation (_not_ the full application to the annotation arguments) to determine its type symbol. pos/unchecked-stable-cyclic-error.scala test case started to fail since scala#8338 with: ``` |-- object Test BYVALmode-EXPRmode (site: package <empty>) | |-- super APPSELmode-EXPRmode-POLYmode-QUALmode (silent: <init> in Test) | | |-- this EXPRmode (silent: <init> in Test) | | | \-> Test.type | | \-> Test.type | |-- def foo BYVALmode-EXPRmode (site: object Test) | | |-- attr EXPRmode (site: method foo in Test) | | | |-- Int TYPEmode (site: method attr in Test) | | | | \-> Int | | | |-- new anno APPSELmode-BYVALmode-EXPRmode-FUNmode-POLYmode (site: object Test) | | | | |-- new anno APPSELmode-EXPRmode-POLYmode-QUALmode (site: object Test) | | | | | |-- anno FUNmode-TYPEmode (site: object Test) | | | | | | \-> anno | | | | | \-> anno | | | | \-> (a: Any): anno | | | |-- (a: Any): anno : pt=anno EXPRmode (site: value <local Test> in Test) | | | | |-- foo : pt=Any BYVALmode-EXPRmode (site: value <local Test> in Test) | | | | | caught scala.reflect.internal.Symbols$CyclicReference: illegal cyclic reference involving method foo: while typing foo /Users/jz/code/scala/sandbox/test.scala:7: error: recursive method foo needs result type @anno(foo) def attr: Int = foo ^ | | | | \-> anno ``` Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of scala#8338). Backporting this fix makes that test start passing on 2.12.x. Backports scala#9302
Make annotation typechecking lazier
Now that
Typer.stabilizeends up checking for@uncheckedStableannotations to support defs's as stable paths, new opportunities arise for cyclic errors.This PR reduces the likelihood of cycles by typechecking the only core of an annotation (not the full application to the annotation arguments) to determine its type symbol.
pos/unchecked-stable-cyclic-error.scala test case started to fail since #8338 with:
Another variant, pos/annotation-cycle.scala, fails only on 2.12.x (after the backport of #8338). Backporting this fix makes that test start passing on 2.12.x.
References scala/bug#12216 (which will be fixed after this is backported to 2.12.x)
Fixes scala/bug#11870