-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4297: handle type param reference #4298
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -88,19 +88,33 @@ object Checkable { | |
} | ||
} | ||
|
||
def stripTypeParam(implicit ctx: Context) = new ApproximatingTypeMap { | ||
def apply(tp: Type): Type = tp match { | ||
case tp: TypeRef if tp.underlying.isInstanceOf[TypeBounds] => | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably equivalent to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
val lo = this(tp.info.loBound) | ||
val hi = this(tp.info.hiBound) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace |
||
range(lo, hi) | ||
case _ => | ||
mapOver(tp) | ||
} | ||
} | ||
|
||
def isClassDetermined(X: Type, P: AppliedType)(implicit ctx: Context) = { | ||
val AppliedType(tycon, _) = P | ||
val typeLambda = tycon.ensureLambdaSub.asInstanceOf[TypeLambda] | ||
val tvars = constrained(typeLambda, untpd.EmptyTree, alwaysAddTypeVars = true)._2.map(_.tpe) | ||
val P1 = tycon.appliedTo(tvars) | ||
|
||
debug.println("P : " + P.show) | ||
debug.println("P1 : " + P1.show) | ||
debug.println("X : " + X.show) | ||
debug.println("P : " + P) | ||
debug.println("P1 : " + P1) | ||
debug.println("X : " + X) | ||
|
||
P1 <:< X // constraint P1 | ||
|
||
P1 <:< X // may fail, ignore | ||
// use fromScala2x to avoid generating pattern bound symbols | ||
maximizeType(P1, pos, fromScala2x = true) | ||
|
||
val res = isFullyDefined(P1, ForceDegree.noBottom) && P1 <:< P | ||
val res = P1 <:< P | ||
debug.println("P1 : " + P1) | ||
debug.println("P1 <:< P = " + res) | ||
|
||
|
@@ -116,7 +130,9 @@ object Checkable { | |
case defn.ArrayOf(tpE) => recur(tpE, tpT) | ||
case _ => recur(defn.AnyType, tpT) | ||
} | ||
case tpe: AppliedType => isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) | ||
case tpe: AppliedType => | ||
isClassDetermined(X, tpe)(ctx.fresh.setNewTyperState()) || | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Here, you first try without stripping type parameters for performance reasons? Maybe add a comment |
||
isClassDetermined(stripTypeParam.apply(X), tpe)(ctx.fresh.setNewTyperState()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Call it as There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It seems scalac has problem with this syntax, however, I've changed the method so we don't need to call |
||
case AndType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) | ||
case OrType(tp1, tp2) => recur(X, tp1) && recur(X, tp2) | ||
case AnnotatedType(t, _) => recur(X, t) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class Test { | ||
def test[X <: Option[Int]](x: X) = x.isInstanceOf[Some[Int]] | ||
def test1[Y <: Int, X <: Option[Y]](x: X) = x.isInstanceOf[Some[Int]] | ||
def test2(x: Any) = x.isInstanceOf[Function1[Nothing, _]] | ||
def test3a(x: Any) = x.isInstanceOf[Function1[Any, _]] // error | ||
def test3b(x: Any) = x.isInstanceOf[Function1[Int, _]] // error | ||
def test4[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, _]] // error | ||
def test5[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Unit]] // error | ||
def test6[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[Int, Any]] // error | ||
def test7[Y <: Int, X <: Function1[Y, Unit]](x: X) = x.isInstanceOf[Function1[_, Unit]] | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a comment:
/** Approximate type parameters depending on variance */