diff options
author | Olivier Blanvillain <olivier.blanvillain@gmail.com> | 2016-09-07 10:06:46 +0200 |
---|---|---|
committer | Olivier Blanvillain <olivier.blanvillain@gmail.com> | 2016-09-08 09:06:34 +0200 |
commit | 006e233c6ab457a1851274b6d3ff457352e98dac (patch) | |
tree | 9fc975d730bc7aa03bcb6dd629846710a5ae45e2 | |
parent | fbb9dba1a2a98f60bdb62d11113a6fea844857db (diff) | |
download | dotty-006e233c6ab457a1851274b6d3ff457352e98dac.tar.gz dotty-006e233c6ab457a1851274b6d3ff457352e98dac.tar.bz2 dotty-006e233c6ab457a1851274b6d3ff457352e98dac.zip |
Fix #1335: Generate null checks for extractors
-rw-r--r-- | src/dotty/tools/dotc/transform/PatternMatcher.scala | 10 | ||||
-rw-r--r-- | tests/pos/t1335.scala | 11 |
2 files changed, 18 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 30b94623d..490feb7d0 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -253,9 +253,13 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer { ) } else { assert(defn.isProductSubType(prev.tpe)) - Block( - List(ValDef(b.asTerm, prev)), - next //Substitution(b, ref(prevSym))(next) + val nullCheck: Tree = prev.select(defn.Object_ne).appliedTo(Literal(Constant(null))) + ifThenElseZero( + nullCheck, + Block( + List(ValDef(b.asTerm, prev)), + next //Substitution(b, ref(prevSym))(next) + ) ) } } diff --git a/tests/pos/t1335.scala b/tests/pos/t1335.scala new file mode 100644 index 000000000..047f7b566 --- /dev/null +++ b/tests/pos/t1335.scala @@ -0,0 +1,11 @@ +case class MyTuple(a: Int, b: Int) + +object Test { + def main(args: Array[String]): Unit = + try { + val mt: MyTuple = null + val MyTuple(a, b) = mt + } catch { + case e: MatchError => () + } +} |