diff options
author | Dmitry Petrashko <dark@d-d.me> | 2015-02-13 14:31:58 +0100 |
---|---|---|
committer | Dmitry Petrashko <dark@d-d.me> | 2015-02-13 14:31:58 +0100 |
commit | 2e72811fb1cedb94c7967acf96c92172f010a20b (patch) | |
tree | 621fd55bf3967fe734d0192cb491ab0e01bc627b /src/dotty/tools/dotc/transform/Erasure.scala | |
parent | c12f21306ea01bd0411f07074a5a0637f23187ff (diff) | |
parent | 37c2dcc2268e6840cfcd89fc5937d461a493e1fd (diff) | |
download | dotty-2e72811fb1cedb94c7967acf96c92172f010a20b.tar.gz dotty-2e72811fb1cedb94c7967acf96c92172f010a20b.tar.bz2 dotty-2e72811fb1cedb94c7967acf96c92172f010a20b.zip |
Merge pull request #359 from dotty-staging/fix/erasure-lub-alternative
Fix/erasure lub alternative
Diffstat (limited to 'src/dotty/tools/dotc/transform/Erasure.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/Erasure.scala | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/src/dotty/tools/dotc/transform/Erasure.scala b/src/dotty/tools/dotc/transform/Erasure.scala index e8fdcd81c..935482ef0 100644 --- a/src/dotty/tools/dotc/transform/Erasure.scala +++ b/src/dotty/tools/dotc/transform/Erasure.scala @@ -251,7 +251,7 @@ object Erasure extends TypeTestsCasts{ override def typedLiteral(tree: untpd.Literal)(implicit ctc: Context): Literal = if (tree.typeOpt.isRef(defn.UnitClass)) tree.withType(tree.typeOpt) else super.typedLiteral(tree) - + /** Type check select nodes, applying the following rewritings exhaustively * on selections `e.m`, where `OT` is the type of the owner of `m` and `ET` * is the erased type of the selection's original qualifier expression. @@ -387,9 +387,29 @@ object Erasure extends TypeTestsCasts{ } } + // The following four methods take as the proto-type the erasure of the pre-existing type, + // if the original proto-type is not a value type. + // This makes all branches be adapted to the correct type. override def typedSeqLiteral(tree: untpd.SeqLiteral, pt: Type)(implicit ctx: Context) = super.typedSeqLiteral(tree, erasure(tree.typeOpt)) - // proto type of typed seq literal is original type; this makes elements be adapted to correct type. + // proto type of typed seq literal is original type; + + override def typedIf(tree: untpd.If, pt: Type)(implicit ctx: Context) = + super.typedIf(tree, adaptProto(tree, pt)) + + override def typedMatch(tree: untpd.Match, pt: Type)(implicit ctx: Context) = + super.typedMatch(tree, adaptProto(tree, pt)) + + override def typedTry(tree: untpd.Try, pt: Type)(implicit ctx: Context) = + super.typedTry(tree, adaptProto(tree, pt)) + + private def adaptProto(tree: untpd.Tree, pt: Type)(implicit ctx: Context) = { + if (pt.isValueType) pt else { + if(tree.typeOpt.derivesFrom(ctx.definitions.UnitClass)) + tree.typeOpt + else erasure(tree.typeOpt) + } + } override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(implicit ctx: Context): ValDef = super.typedValDef(untpd.cpy.ValDef(vdef)( |