-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Compiler crash when annotated types contain certain trees #17939
Comments
Output when adding
|
Could the culprit be the following? Should we map symbols in this case? |
Just to see if it changes something, I tried to always map symbols to fresh ones in diff --git a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
index ac3dc15092a..43409e5125b 100644
--- a/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
+++ b/compiler/src/dotty/tools/dotc/transform/PostTyper.scala
@@ -19,6 +19,7 @@ import config.Feature
import util.SrcPos
import reporting._
import NameKinds.WildcardParamName
+import dotty.tools.dotc.ast.TreeTypeMap
object PostTyper {
val name: String = "posttyper"
@@ -84,6 +85,12 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
val synthMbr: SyntheticMembers = new SyntheticMembers(thisPhase)
val beanProps: BeanProperties = new BeanProperties(thisPhase)
+ def withFreshSymbols(tree: Tree)(using Context): Tree =
+ val tm = new TreeTypeMap():
+ override def withMappedSyms(syms: List[Symbol]): TreeTypeMap =
+ withMappedSyms(syms, mapSymbols(syms, this, mapAlways = true))
+ tm(tree)
+
private def newPart(tree: Tree): Option[New] = methPart(tree) match {
case Select(nu: New, _) => Some(nu)
case _ => None
@@ -135,7 +142,9 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
val saved = inJavaAnnot
inJavaAnnot = annot.symbol.is(JavaDefined)
if (inJavaAnnot) checkValidJavaAnnotation(annot)
- try transform(annot)
+ try
+ val res = transform(annot)
+ if res != annot then withFreshSymbols(res) else annot
finally inJavaAnnot = saved
} With this change, the file compiles, but the pickling test fails: $ diff before-pickling.txt after-pickling.txt
50,52c50,51
< x: scala.Int@tests/pos/tasty-no-address.scala<149..152>@tests/pos/tasty-no-address.scala[146..152]@@(x=
< tests/pos/tasty-no-address.scala:<146..146>)
< ): scala.Boolean =
---
> x: scala.Int@tests/pos/tasty-no-address.scala<149..152>@tests/pos/tasty-no-address.scala<149..152>@@(x=?))
> : scala.Boolean =
64,66c63,65
< tests/pos/tasty-no-address.scala<157..163>
< .x:scala.Int>@tests/pos/tasty-no-address.scala<157..165>
< .==:((x: scala.Int): scala.Boolean)>@tests/pos/tasty-no-address.scala<157..168>
---
> tests/pos/tasty-no-address.scala<157..162>
> .x:scala.Int>@tests/pos/tasty-no-address.scala<157..162>
> .==:((x: scala.Int): scala.Boolean)>@tests/pos/tasty-no-address.scala<157..162>
69,71c68,70
< @tests/pos/tasty-no-address.scala[145..154..170]@@($anonfun=tests/pos/tasty-no-address.scala:<154..154>)
< <closure(<$anonfun:(x: scala.Int): scala.Boolean>@tests/pos/tasty-no-address.scala<170..170>):scala.Int =>
< scala.Boolean>@tests/pos/tasty-no-address.scala<170..170>
---
> @tests/pos/tasty-no-address.scala<149..152>@@($anonfun=?)
> <closure(<$anonfun:(x: scala.Int): scala.Boolean>@tests/pos/tasty-no-address.scala<152..152>):scala.Int =>
> scala.Boolean>@tests/pos/tasty-no-address.scala<152..152>
73c72
< :scala.Int => scala.Boolean>@tests/pos/tasty-no-address.scala<145..170>
---
> :scala.Int => scala.Boolean>@tests/pos/tasty-no-address.scala<149..152> |
The Maybe we should special case the |
Minimizing a different failing case, I found the following, which I think is related: import scala.annotation.Annotation
class myRefined(f: ? => Boolean) extends Annotation
def test(axes: Int) = true
trait Tensor:
def mean(axes: Int): Int @myRefined(_ => test(axes))
class TensorImpl() extends Tensor:
def mean(axes: Int) = ??? Both the lambda and the subclassing appear to be necessary Here is the error: Click to expand
|
Compiler version
348729e
Minimized code
Output (click arrow to expand)
Trees with IDs after
posttyper
Look at the blocks in the annotations in
A
: one has ID#1182
and one has the ID#1202
, but the innerdef $anonfun
and associated symbol are the same, hence the problem. The typesString @myRefined
are also different.In
A2
however, both blocks have ID#1032
and bothString @myRefined
have id#1232
.The text was updated successfully, but these errors were encountered: