Skip to content

Commit 6d6da11

Browse files
committed
Fix mapping of annotations
We previously did not do an (expensive) TreeTypeMap on an annotation if the mapped versions of all types of subtrees of the annotation tree were =:= to the original types. But it turns out this is too coarse. In the test we have capture set variables where we intend to map a TypeRef to a TypeParamRef but the two were considered as =:= because of the bounds they had. So no mapping took place. We now use `eql` instead of =:=, which is structural comparison with `eq` for references to corresponding binders.
1 parent a50a1e4 commit 6d6da11

File tree

5 files changed

+19
-1
lines changed

5 files changed

+19
-1
lines changed

compiler/src/dotty/tools/dotc/core/Annotations.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ object Annotations {
6565
if tm.isRange(x) then x
6666
else
6767
val tp1 = tm(tree.tpe)
68-
foldOver(if !tp1.exists || (tp1 frozen_=:= tree.tpe) then x else tp1, tree)
68+
foldOver(if !tp1.exists || tp1.eql(tree.tpe) then x else tp1, tree)
6969
val diff = findDiff(NoType, args)
7070
if tm.isRange(diff) then EmptyAnnotation
7171
else if diff.exists then derivedAnnotation(tm.mapOver(tree))

compiler/src/dotty/tools/dotc/core/Types.scala

+2
Original file line numberDiff line numberDiff line change
@@ -6322,6 +6322,8 @@ object Types extends TypeUtils {
63226322
override def stopAt = thisMap.stopAt
63236323
def apply(tp: Type) = f(thisMap(tp))
63246324
}
6325+
6326+
override def toString = s"${getClass.getSimpleName}@$hashCode" // otherwise would print as <function1>
63256327
}
63266328

63276329
/** A type map that maps also parents and self type of a ClassInfo */
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// a.scala
2+
import language.experimental.captureChecking
3+
import scala.caps.CapSet
4+
5+
trait A:
6+
def f[C^](x: AnyRef^{C^}): Unit
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import language.experimental.captureChecking
2+
import scala.caps.CapSet
3+
4+
class B extends A:
5+
def f[C^](x: AnyRef^{C^}): Unit = ???
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import language.experimental.captureChecking
2+
import scala.caps.CapSet
3+
4+
class B extends A:
5+
def f[C^](x: AnyRef^{C^}): Unit = ???

0 commit comments

Comments
 (0)