Skip to content

Commit 413747f

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 =typcon1.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 } ```
1 parent 13428d9 commit 413747f

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

compiler/test/dotty/tools/AnnotationsTests.scala

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,23 @@ class AnnotationsTest:
2626
val defn = ctx.definitions
2727
val cls = requiredClass("A")
2828
val annotCls = requiredClass("Annot")
29-
val arrayOfString = defn.ArrayType.appliedTo(List(defn.StringType))
29+
val arrayOfString = defn.ArrayOf(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)