From 7c0c1f31fda704e790ca7a9d260c8c956b28d447 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Sun, 17 Jul 2016 20:41:13 +0200 Subject: Fix typing of match expressions Allow matches between unapply types and selector type where a possible overlap might exist. --- tests/neg/i1212.scala | 1 + 1 file changed, 1 insertion(+) create mode 100644 tests/neg/i1212.scala (limited to 'tests') diff --git a/tests/neg/i1212.scala b/tests/neg/i1212.scala new file mode 100644 index 000000000..b009a4d2c --- /dev/null +++ b/tests/neg/i1212.scala @@ -0,0 +1 @@ +@ann class ann extends scala.annotation.Annotation // error: cyclic reference -- cgit v1.2.3 From 60be18cce509bae1ed0d6c68b910f4bed10fa889 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Jul 2016 12:55:07 +0200 Subject: Add test case Also fix reviewers comments about `firstParent` --- src/dotty/tools/dotc/typer/Applications.scala | 2 +- tests/neg/patmat.scala | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/neg/patmat.scala (limited to 'tests') diff --git a/src/dotty/tools/dotc/typer/Applications.scala b/src/dotty/tools/dotc/typer/Applications.scala index f7a96c6b4..262e6a087 100644 --- a/src/dotty/tools/dotc/typer/Applications.scala +++ b/src/dotty/tools/dotc/typer/Applications.scala @@ -751,7 +751,7 @@ trait Applications extends Compatibility { self: Typer with Dynamic => if (subtp <:< tp) true else tp match { case tp: TypeRef if tp.symbol.isClass => - tp.symbol.is(Trait) && isSubTypeOfParent(subtp, tp.parents.head) + tp.symbol.is(Trait) && isSubTypeOfParent(subtp, tp.firstParent) case tp: TypeProxy => isSubTypeOfParent(subtp, tp.superType) case _ => false } diff --git a/tests/neg/patmat.scala b/tests/neg/patmat.scala new file mode 100644 index 000000000..e2ab9874e --- /dev/null +++ b/tests/neg/patmat.scala @@ -0,0 +1,24 @@ +trait A +trait B +class C extends A with B +case class D() +object X { + def unapply(x: B): Boolean = false +} + +object Test { + def main(args: Array[String]) = { + val ca: A = new C + ca match { + case x: B => + case X() => + case D() => // error: neither a subtype not a supertype + } + val cc = new C + cc match { + case x: B => + case X() => + case D() => // error: neither a subtype not a supertype + } + } +} -- cgit v1.2.3 From 198817b3d55f3a3df4f320622e60515f05da3aa0 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 18 Jul 2016 15:25:08 +0200 Subject: Fix test error annotation --- tests/neg/patmat.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/neg/patmat.scala b/tests/neg/patmat.scala index e2ab9874e..1e72c104a 100644 --- a/tests/neg/patmat.scala +++ b/tests/neg/patmat.scala @@ -12,7 +12,7 @@ object Test { ca match { case x: B => case X() => - case D() => // error: neither a subtype not a supertype + case D() => // ok, but scalac disagrees } val cc = new C cc match { -- cgit v1.2.3