Skip to content

Commit

Permalink
Merge pull request #1981 from retronym/backport/1187
Browse files Browse the repository at this point in the history
[backport] SI-3577 BoundedWildcardType handling
  • Loading branch information
adriaanm committed Jan 29, 2013
2 parents d392d56 + b8da00e commit eff78b8
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/compiler/scala/tools/nsc/typechecker/RefChecks.scala
Expand Up @@ -905,13 +905,15 @@ abstract class RefChecks extends InfoTransform with scala.reflect.internal.trans
* the type occurs itself at variance position given by `variance`
*/
def validateVariance(tp: Type, variance: Int): Unit = tp match {
case ErrorType => ;
case WildcardType => ;
case NoType => ;
case NoPrefix => ;
case ThisType(_) => ;
case ConstantType(_) => ;
// case DeBruijnIndex(_, _) => ;
case ErrorType =>
case WildcardType =>
case BoundedWildcardType(bounds) =>
validateVariance(bounds, variance)
case NoType =>
case NoPrefix =>
case ThisType(_) =>
case ConstantType(_) =>
// case DeBruijnIndex(_, _) =>
case SingleType(pre, sym) =>
validateVariance(pre, variance)
case TypeRef(pre, sym, args) =>
Expand Down
2 changes: 2 additions & 0 deletions src/compiler/scala/tools/nsc/typechecker/Variances.scala
Expand Up @@ -67,6 +67,8 @@ trait Variances {
def varianceInType(tp: Type)(tparam: Symbol): Int = tp match {
case ErrorType | WildcardType | NoType | NoPrefix | ThisType(_) | ConstantType(_) =>
VARIANCES
case BoundedWildcardType(bounds) =>
varianceInType(bounds)(tparam)
case SingleType(pre, sym) =>
varianceInType(pre)(tparam)
case TypeRef(pre, sym, args) =>
Expand Down
2 changes: 2 additions & 0 deletions src/reflect/scala/reflect/internal/Types.scala
Expand Up @@ -22,6 +22,8 @@ import util.ThreeValues._
// internal: error
case WildcardType =>
// internal: unknown
case BoundedWildcardType(bounds) =>
// internal: unknown
case NoType =>
case NoPrefix =>
case ThisType(sym) =>
Expand Down
29 changes: 29 additions & 0 deletions test/files/pos/t3577.scala
@@ -0,0 +1,29 @@
case class Check[A](val value: A)

case class C2(checks: Check[_]*);

object C {
def m(x : C2): Any = (null: Any) match {
case C2(_, rest @ _*) => {
rest.map(_.value)
}
}
}

///////////////////

object Container {
trait Exp[+T]
abstract class FuncExp[-S, +T]

sealed abstract class FoundNode[T, Repr] {
def optimize[TupleT, U, That](parentNode: FlatMap[T, Repr, U, That]): Any
def optimize2[TupleT, U, That](parentNode: Any): Any
}

class FlatMap[T, Repr, U, That]

val Seq(fn: FoundNode[t, repr]) = Seq[FoundNode[_, _]]()
fn.optimize(null) // was: scala.MatchError: ? (of class BoundedWildcardType) @ Variances#varianceInType
fn.optimize2(null) // was: fatal error: bad type: ?(class scala.reflect.internal.Types$BoundedWildcardType) @ Pickle.putType
}

0 comments on commit eff78b8

Please sign in to comment.