Skip to content

Commit 03a06e0

Browse files
committed
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
1 parent 185ff4c commit 03a06e0

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ trait Kinds {
185185
)
186186
}
187187
else {
188+
hkarg.initialize // SI-7902 otherwise hkarg.typeParams yields List(NoSymbol)!
188189
debuglog("checkKindBoundsHK recursing to compare params of "+ hkparam +" with "+ hkarg)
189190
kindErrors ++= checkKindBoundsHK(
190191
hkarg.typeParams,

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)