Skip to content

Commit 9021afb

Browse files
committed
Fix test
We have the following subtyping result: ```scala Subtype trace: ==> Array#262[String#810] <:< Array#262[String#810] ==> Array#262[String#810] <:< Array#262[String#810] recur <== Array#262[String#810] <:< Array#262[String#810] recur = false <== Array#262[String#810] <:< Array#262[String#810] = false ``` In `TypeComparer.compareAppliedType2`, the method just returns false because `typcon2.typeParams` is empty: ``` def compareAppliedType2(tp2: AppliedType, tycon2: Type, args2: List[Type]): Boolean = { val tparams = tycon2.typeParams if (tparams.isEmpty) return false ``` The reason why `ftypcon1.typeParams` is empty is because we are running the subtyping check after erasure. The following code works without any problem: ```scala atPhase(typerPhase) { arrayOfString =:= arg.tpe } ``` Before the change the two `Array[String]` and `Array[String]` point to the same object, thus they go through the short-cut `tp1 eq tp2` in `TypeComparer`, thus never reaches the line `TypeComparer.compareAppliedType2`.
1 parent d8930c6 commit 9021afb

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

compiler/test/dotty/tools/AnnotationsTests.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,20 @@ class AnnotationsTest:
2929
val arrayOfString = defn.ArrayType.appliedTo(List(defn.StringType))
3030

3131
atPhase(erasurePhase.next) {
32-
val annot = cls.getAnnotation(annotCls)
3332
// Even though we're forcing the annotation after erasure,
3433
// the typed trees should be unerased, so the type of
3534
// the annotation argument should be `arrayOfString` and
3635
// not a `JavaArrayType`.
36+
val annot = cls.getAnnotation(annotCls)
3737
val arg = annot.get.argument(0).get
38-
assert(arg.tpe.isInstanceOf[AppliedType] && arg.tpe =:= arrayOfString,
38+
39+
// If we run the type check after erasure, we will have
40+
// `Array[String] =:= Array[String]` being false.
41+
// The reason is that in `TypeComparer.compareAppliedType2` we have
42+
// `tycon2.typeParams == Nil` after erasure, thus always get false.
43+
val res = atPhase(typerPhase) { arrayOfString =:= arg.tpe }
44+
45+
assert(arg.tpe.isInstanceOf[AppliedType] && res,
3946
s"Argument $arg had type:\n${arg.tpe}\nbut expected type:\n$arrayOfString")
4047
}
4148
}

0 commit comments

Comments
 (0)