-
Notifications
You must be signed in to change notification settings - Fork 21
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
uncheckedStable backport to 2.12.x caused regression in annotations #12216
Comments
The relevant difference between 2.12.x and 2.13.x appears to be scala/scala#6092, the change to unconditionally parse It is possible however that other code patterns could trigger this new cyclic error in 2.13.x. |
Here is a program that incurs a cyclic error in 2.13.x since the scala/scala#8338. import scala.annotation.StaticAnnotation
class anno(a: Any) extends StaticAnnotation
object Test {
def foo = attr
@anno(foo) def attr: Int = foo
}
|
Here's another take at avoiding these cycles. We could introduce an extra layer of lazy typechecking for annotations. In the first phase, we typecheck the |
An alternative (or complementary) remedy would be to change the order of evaluation of: def isModuleTypedExpr = (
treeInfo.admitsTypeSelection(tree)
&& (isStableContext(tree, mode, pt) || sym.isModuleNotMethod)
) The call to |
Now that `Typer.stabilize` ends up checking for `@uncheckedStable` annotations to support defs's as stable paths, new opportunities arise for cyclic errors. The enclosed 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 detailed in scala/bug#12216 fails only on 2.12.x (after the backport of scala#8338). Backporting this fix will fix that problem, too. This reduces the likelihood of cycles by typechecking the only core of an annotation (_not_ the full application to the annotation argumnets) to determine its type symbol.
reproduction steps
using Scala 2.12.13-bin-b08ccde
problem
The problem doesn't exist in 2.13.x (where
@uncheckedStable
support was authored. Maybe some other change on that branch avoids the problem?I'm trying fixes in retronym/scala#104
The text was updated successfully, but these errors were encountered: