Skip to content

Commit 5f4011e

Browse files
committed
[backport] SI-7902 Fix spurious kind error due to an unitialized symbol
Tracked down this error: <none> is invariant, but type Y2 is declared covariant <none>'s bounds<notype> are stricter than type X2's declared bounds >: Nothing <: Any, <none>'s bounds<notype> are stricter than type Y2's declared bounds >: Nothing <: Any to `Symbol#typeParams` returning `List(NoSymbol)` if the symbol was not initialized. This happends in the enclosed test for: // checkKindBoundsHK() hkArgs = List(type M3) hkParams = List(type M2) This commit forces the symbol of the higher-kinded type argument before checking kind conformance. A little backstory: The `List(NoSymbol)` arises from: class PolyTypeCompleter... { // @m. If `owner` is an abstract type member, `typeParams` are all NoSymbol (see comment in `completerOf`), // otherwise, the non-skolemized (external) type parameter symbols override val typeParams = tparams map (_.symbol) The variation that triggers this problem gets into the kind conformance checks quite early on, during naming of: private[this] val x = ofType[InSeq] The inferred type of which is forced during: def addDerivedTrees(typer: Typer, stat: Tree): List[Tree] = stat match { case vd @ ValDef(mods, name, tpt, rhs) if !noFinishGetterSetter(vd) => // If we don't save the annotations, they seem to wander off. val annotations = stat.symbol.initialize.annotations (cherry picked from commit 03a06e0)
1 parent 5720e97 commit 5f4011e

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/reflect/scala/reflect/internal/Kinds.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,7 @@ trait Kinds {
184184
)
185185
}
186186
else {
187+
hkarg.initialize // SI-7902 otherwise hkarg.typeParams yields List(NoSymbol)!
187188
debuglog("checkKindBoundsHK recursing to compare params of "+ hkparam +" with "+ hkarg)
188189
kindErrors ++= checkKindBoundsHK(
189190
hkarg.typeParams,
@@ -229,4 +230,4 @@ trait Kinds {
229230
}
230231
}
231232
}
232-
}
233+
}

test/files/pos/t7902.scala

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import scala.language.higherKinds
2+
3+
object Bug {
4+
class Tag[W[M1[X1]]]
5+
6+
def ofType[W[M2[X2]]]: Tag[W] = ???
7+
type InSeq [M3[X3]] = Some[M3[Any]]
8+
9+
// fail
10+
val x = ofType[InSeq]
11+
12+
// okay
13+
val y: Any = ofType[InSeq]
14+
object T {
15+
val z = ofType[InSeq]
16+
}
17+
}

0 commit comments

Comments
 (0)