From 4cb4ad76b213389b828ae9c1ab26c9d7a1c3a7c2 Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Sat, 17 Oct 2009 12:36:14 +0000 Subject: Fix and test cases for ticket #443. flags on AnyVal from FINAL|SEALED to ABSTRACT|SEALED. This appears correct and without ill effect, but if anyone spots new anyval oddness you know where to look. --- .../scala/tools/nsc/matching/MatrixAdditions.scala | 10 +++----- .../scala/tools/nsc/symtab/Definitions.scala | 2 +- test/files/jvm/interpreter.check | 1 + test/files/neg/patmatexhaust.check | 9 +++++-- test/files/neg/patmatexhaust.scala | 28 +++++++++++++++++++--- 5 files changed, 37 insertions(+), 13 deletions(-) diff --git a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala index 4a1a423b7f..37ddbbc671 100644 --- a/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala +++ b/src/compiler/scala/tools/nsc/matching/MatrixAdditions.scala @@ -198,14 +198,10 @@ trait MatrixAdditions extends ast.TreeDSL { s resetFlag MUTABLE ; true } // side effects MUTABLE flag private def sealedSymsFor(s: Symbol): Set[Symbol] = { - def countSealed(child: Symbol) = { - // include base class only if non-abstract - def baseSet = if (child hasFlag ABSTRACT) Set() else Set(child) - sealedSymsFor(child) ++ baseSet - } - if (s hasFlag SEALED) s.children flatMap countSealed - else Set() + val kids = s.children flatMap sealedSymsFor + if (s hasFlag ABSTRACT) kids else kids + s } + private lazy val inexhaustives: List[List[Combo]] = { val collected = for ((pv, i) <- tvars.zipWithIndex ; val sym = pv.lhs ; if requiresExhaustive(sym)) yield diff --git a/src/compiler/scala/tools/nsc/symtab/Definitions.scala b/src/compiler/scala/tools/nsc/symtab/Definitions.scala index 9c2df4a6cb..6aa18d583f 100644 --- a/src/compiler/scala/tools/nsc/symtab/Definitions.scala +++ b/src/compiler/scala/tools/nsc/symtab/Definitions.scala @@ -53,7 +53,7 @@ trait Definitions { // top types lazy val AnyClass = newClass(ScalaPackageClass, nme.Any, Nil) setFlag (ABSTRACT) - lazy val AnyValClass = newClass(ScalaPackageClass, nme.AnyVal, anyparam) setFlag (FINAL | SEALED) + lazy val AnyValClass = newClass(ScalaPackageClass, nme.AnyVal, anyparam) setFlag (ABSTRACT | SEALED) lazy val AnyRefClass = newAlias(ScalaPackageClass, nme.AnyRef, ObjectClass.typeConstructor) lazy val ObjectClass = getClass(sn.Object) diff --git a/test/files/jvm/interpreter.check b/test/files/jvm/interpreter.check index 27f8be2f57..e17cc15a0a 100644 --- a/test/files/jvm/interpreter.check +++ b/test/files/jvm/interpreter.check @@ -219,6 +219,7 @@ defined class Term scala> | | :15: warning: match is not exhaustive! missing combination Term +missing combination Exp def f(e: Exp) = e match { // non-exhaustive warning here ^ diff --git a/test/files/neg/patmatexhaust.check b/test/files/neg/patmatexhaust.check index 66b0f3c8ea..1c46b6c9e5 100644 --- a/test/files/neg/patmatexhaust.check +++ b/test/files/neg/patmatexhaust.check @@ -25,8 +25,13 @@ missing combination Gp def ma5(x:Deep) = x match { // Gp ^ -patmatexhaust.scala:70: error: unreachable code +patmatexhaust.scala:75: warning: match is not exhaustive! +missing combination B + + def ma9(x: B) = x match { + ^ +patmatexhaust.scala:92: error: unreachable code case 1 => ^ -5 warnings found +6 warnings found one error found diff --git a/test/files/neg/patmatexhaust.scala b/test/files/neg/patmatexhaust.scala index b2d0b8ddd2..ffb37f3be6 100644 --- a/test/files/neg/patmatexhaust.scala +++ b/test/files/neg/patmatexhaust.scala @@ -1,5 +1,5 @@ class TestSealedExhaustive { // compile only - sealed class Foo + sealed abstract class Foo case class Bar(x:Int) extends Foo case object Baz extends Foo @@ -12,7 +12,7 @@ class TestSealedExhaustive { // compile only case Baz => // not exhaustive } - sealed class Mult + sealed abstract class Mult case class Kult(s:Mult) extends Mult case class Qult() extends Mult @@ -32,7 +32,7 @@ class TestSealedExhaustive { // compile only case (Qult(), Kult(_)) => } - sealed class Deep + sealed abstract class Deep case object Ga extends Deep sealed class Gp extends Deep @@ -65,6 +65,28 @@ class TestSealedExhaustive { // compile only case 1::2::Nil => case _ => } + + sealed class B + case class B1 extends B + case object B2 extends B + def ma8(x: B) = x match { + case _: B => true + } + def ma9(x: B) = x match { + case B1() => true // missing B, which is not abstract so must be included + case B2 => true + } + sealed abstract class C + abstract class C1 extends C + object C2 extends C + case object C6 extends C + class C3 extends C1 + case class C4 extends C3 + def ma10(x: C) = x match { // exhaustive + case C4() => true + case C2 | C6 => true + } + def redundant = 1 match { // include this otherwise script won't test this in files/neg case 1 => case 1 => -- cgit v1.2.3