From 619402025124d05dfdaf6b32c46bf66deb4b4da7 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sat, 20 Feb 2016 17:04:18 +0100 Subject: [PATCH 1/2] PatMat: remove one more trace of doing several steps at a time When creating subPatRefs the consider returned type of accessor, not the type of binder. Fixes #1114 --- src/dotty/tools/dotc/transform/PatternMatcher.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dotty/tools/dotc/transform/PatternMatcher.scala b/src/dotty/tools/dotc/transform/PatternMatcher.scala index 4d626c67bd5d..b4e32fa66524 100644 --- a/src/dotty/tools/dotc/transform/PatternMatcher.scala +++ b/src/dotty/tools/dotc/transform/PatternMatcher.scala @@ -1543,7 +1543,7 @@ class PatternMatcher extends MiniPhaseTransform with DenotTransformer {thisTrans val spb = subPatBinders ExtractorTreeMaker(extractorApply, lengthGuard(binder), binder)( spb, - subPatRefs(binder, spb, binderTypeTested), + subPatRefs(binder, spb, resultType), aligner.isBool, checkedLength, patBinderOrCasted, From e5c8cb439ef59c0942070e812f1ef634c6ab9451 Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Sat, 20 Feb 2016 17:11:04 +0100 Subject: [PATCH 2/2] Test that #1114 is fixed. --- tests/run/patmat-option-named.scala | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 tests/run/patmat-option-named.scala diff --git a/tests/run/patmat-option-named.scala b/tests/run/patmat-option-named.scala new file mode 100644 index 000000000000..b27d07107709 --- /dev/null +++ b/tests/run/patmat-option-named.scala @@ -0,0 +1,21 @@ +case class HasSingleField(f: HasSingleField) + +object Test { + + def main(args: Array[String]) = { + val s: Object = HasSingleField(null) + s match { + case Matcher(self) => + assert(self ne null) + } + } +} + +object Matcher { + def unapply(x: Object): Option[HasSingleField] = { + if (x.isInstanceOf[HasSingleField]) + Some(x.asInstanceOf[HasSingleField]) + else + None + } +}