diff options
author | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-03 14:15:30 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@epfl.ch> | 2012-06-03 14:15:30 -0700 |
commit | b34313db72b7c42fb403677487bd9ac00257993e (patch) | |
tree | 520fb709066f01bb73a6fa2f2ed900c20ba118ec /src | |
parent | 09f0814d2fbad488e92c60d7df363d12f350d869 (diff) | |
parent | 80d986997e58b5195654b6f9ca8cd81bc62f4bbf (diff) | |
download | scala-b34313db72b7c42fb403677487bd9ac00257993e.tar.gz scala-b34313db72b7c42fb403677487bd9ac00257993e.tar.bz2 scala-b34313db72b7c42fb403677487bd9ac00257993e.zip |
Merge pull request #661 from retronym/ticket/5683
SI-5683 Fail gracefully when transposing a ragged type arg matrix.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/reflect/internal/Types.scala | 61 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/util/Collections.scala | 6 |
2 files changed, 38 insertions, 29 deletions
diff --git a/src/compiler/scala/reflect/internal/Types.scala b/src/compiler/scala/reflect/internal/Types.scala index 67c858356c..02e11ddd59 100644 --- a/src/compiler/scala/reflect/internal/Types.scala +++ b/src/compiler/scala/reflect/internal/Types.scala @@ -6572,47 +6572,50 @@ trait Types extends api.Types { self: SymbolTable => else Some(typeRef(pre, sym, List(lub(args)))) } } - else { - val args = map2(sym.typeParams, argss.transpose) { (tparam, as) => - if (depth == 0) { - if (tparam.variance == variance) { - // Take the intersection of the upper bounds of the type parameters - // rather than falling all the way back to "Any", otherwise we end up not - // conforming to bounds. - val bounds0 = sym.typeParams map (_.info.bounds.hi) filterNot (_.typeSymbol == AnyClass) - if (bounds0.isEmpty) AnyClass.tpe - else intersectionType(bounds0 map (b => b.asSeenFrom(tps.head, sym))) + else transposeSafe(argss) match { + case None => + // transpose freaked out because of irregular argss + // catching just in case (shouldn't happen, but also doesn't cost us) + // [JZ] It happens: see SI-5683. + debuglog("transposed irregular matrix!?" +(tps, argss)) + None + case Some(argsst) => + val args = map2(sym.typeParams, argsst) { (tparam, as) => + if (depth == 0) { + if (tparam.variance == variance) { + // Take the intersection of the upper bounds of the type parameters + // rather than falling all the way back to "Any", otherwise we end up not + // conforming to bounds. + val bounds0 = sym.typeParams map (_.info.bounds.hi) filterNot (_.typeSymbol == AnyClass) + if (bounds0.isEmpty) AnyClass.tpe + else intersectionType(bounds0 map (b => b.asSeenFrom(tps.head, sym))) + } + else if (tparam.variance == -variance) NothingClass.tpe + else NoType } - else if (tparam.variance == -variance) NothingClass.tpe - else NoType - } - else { - if (tparam.variance == variance) lub(as, decr(depth)) - else if (tparam.variance == -variance) glb(as, decr(depth)) else { - val l = lub(as, decr(depth)) - val g = glb(as, decr(depth)) - if (l <:< g) l + if (tparam.variance == variance) lub(as, decr(depth)) + else if (tparam.variance == -variance) glb(as, decr(depth)) + else { + val l = lub(as, decr(depth)) + val g = glb(as, decr(depth)) + if (l <:< g) l else { // Martin: I removed this, because incomplete. Not sure there is a good way to fix it. For the moment we // just err on the conservative side, i.e. with a bound that is too high. // if(!(tparam.info.bounds contains tparam)) //@M can't deal with f-bounds, see #2251 - val qvar = commonOwner(as) freshExistential "" setInfo TypeBounds(g, l) - capturedParams += qvar - qvar.tpe + val qvar = commonOwner(as) freshExistential "" setInfo TypeBounds(g, l) + capturedParams += qvar + qvar.tpe + } } } } - } - if (args contains NoType) None - else Some(existentialAbstraction(capturedParams.toList, typeRef(pre, sym, args))) + if (args contains NoType) None + else Some(existentialAbstraction(capturedParams.toList, typeRef(pre, sym, args))) } } catch { case ex: MalformedType => None - case ex: IndexOutOfBoundsException => // transpose freaked out because of irregular argss - // catching just in case (shouldn't happen, but also doesn't cost us) - debuglog("transposed irregular matrix!?"+ (tps, argss)) - None } case SingleType(_, sym) :: rest => val pres = tps map (_.prefix) diff --git a/src/compiler/scala/reflect/internal/util/Collections.scala b/src/compiler/scala/reflect/internal/util/Collections.scala index 2e119f8ccc..1f8eb15c90 100644 --- a/src/compiler/scala/reflect/internal/util/Collections.scala +++ b/src/compiler/scala/reflect/internal/util/Collections.scala @@ -201,6 +201,12 @@ trait Collections { } true } + + final def transposeSafe[A](ass: List[List[A]]): Option[List[List[A]]] = try { + Some(ass.transpose) + } catch { + case _: IllegalArgumentException => None + } } object Collections extends Collections { } |