Skip to content

Commit

Permalink
Merge pull request #1878 from adriaanm/ticket-6925
Browse files Browse the repository at this point in the history
SI-6925 use concrete type in applyOrElse's match's selecto
  • Loading branch information
adriaanm committed Jan 14, 2013
2 parents 1a305a5 + 51f574a commit 9739002
Show file tree
Hide file tree
Showing 5 changed files with 183 additions and 145 deletions.
5 changes: 5 additions & 0 deletions src/compiler/scala/tools/nsc/ast/TreeGen.scala
Expand Up @@ -253,6 +253,11 @@ abstract class TreeGen extends scala.reflect.internal.TreeGen with TreeDSL {
}
}

// drop annotations generated by CPS plugin etc, since its annotationchecker rejects T @cps[U] <: Any
// let's assume for now annotations don't affect casts, drop them there, and bring them back using the outer Typed tree
def mkCastPreservingAnnotations(tree: Tree, pt: Type) =
Typed(mkCast(tree, pt.withoutAnnotations.dealias), TypeTree(pt))

/** Generate a cast for tree Tree representing Array with
* elem type elemtp to expected type pt.
*/
Expand Down
Expand Up @@ -1478,14 +1478,9 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
def _equals(checker: Tree, binder: Symbol): Tree = checker MEMBER_== REF(binder) // NOTE: checker must be the target of the ==, that's the patmat semantics for ya
def and(a: Tree, b: Tree): Tree = a AND b

// drop annotations generated by CPS plugin etc, since its annotationchecker rejects T @cps[U] <: Any
// let's assume for now annotations don't affect casts, drop them there, and bring them back using the outer Typed tree
private def mkCast(t: Tree, tp: Type) =
Typed(gen.mkAsInstanceOf(t, tp.withoutAnnotations, true, false), TypeTree() setType tp)

// the force is needed mainly to deal with the GADT typing hack (we can't detect it otherwise as tp nor pt need contain an abstract type, we're just casting wildly)
def _asInstanceOf(t: Tree, tp: Type): Tree = if (t.tpe != NoType && t.isTyped && typesConform(t.tpe, tp)) t else mkCast(t, tp)
def _asInstanceOf(b: Symbol, tp: Type): Tree = if (typesConform(b.info, tp)) REF(b) else mkCast(REF(b), tp)
def _asInstanceOf(t: Tree, tp: Type): Tree = if (t.tpe != NoType && t.isTyped && typesConform(t.tpe, tp)) t else gen.mkCastPreservingAnnotations(t, tp)
def _asInstanceOf(b: Symbol, tp: Type): Tree = if (typesConform(b.info, tp)) REF(b) else gen.mkCastPreservingAnnotations(REF(b), tp)
def _isInstanceOf(b: Symbol, tp: Type): Tree = gen.mkIsInstanceOf(REF(b), tp.withoutAnnotations, true, false)
// if (typesConform(b.info, tpX)) { patmatDebug("warning: emitted spurious isInstanceOf: "+(b, tp)); TRUE }

Expand Down

0 comments on commit 9739002

Please sign in to comment.