diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 21 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Infer.scala | 3 | ||||
-rw-r--r-- | test/files/pos/bug789.scala | 32 |
3 files changed, 46 insertions, 10 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index c7e59925d5..aa75b710de 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -556,14 +556,14 @@ trait Parsers requires SyntaxAnalyzer { } /** Type1 ::= SimpleType {with SimpleType} [Refinement] - * TypePattern1 ::= SimpleTypePattern [TypePatternArgs] + * TypePattern1 ::= SimpleTypePattern {with SimpleTypePattern} */ def type1(isPattern: boolean): Tree = type1rest(in.currentPos, simpleType(isPattern), isPattern) def type1rest(pos: int, t: Tree, isPattern: boolean): Tree = { var ts = new ListBuffer[Tree] + t - while (in.token == WITH && !isPattern) { + while (in.token == WITH) { in.nextToken(); ts += simpleType(isPattern) } atPos(pos) { @@ -572,14 +572,15 @@ trait Parsers requires SyntaxAnalyzer { } } - /** SimpleType ::= SimpleType TypeArgs - * | SimpleType `#' Id - * | StableId - * | Path `.' type - * | `(' Type `)' - * SimpleTypePattern ::= SimpleTypePattern "#" Id - * | StableId - * | Path `.' type) + /** SimpleType ::= SimpleType TypeArgs + * | SimpleType `#' Id + * | StableId + * | Path `.' type + * | `(' Type `)' + * SimpleTypePattern ::= SimpleTypePattern TypePatternArgs + * | SimpleTypePattern1 "#" Id + * | StableId + * | Path `.' type */ def simpleType(isPattern: boolean): Tree = { val pos = in.currentPos diff --git a/src/compiler/scala/tools/nsc/typechecker/Infer.scala b/src/compiler/scala/tools/nsc/typechecker/Infer.scala index 9f1d17fc8c..0d2d65567d 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Infer.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Infer.scala @@ -810,6 +810,9 @@ trait Infer requires Analyzer { } } checkCheckable(pos, pre) + case RefinedType(parents, decls) => + if (decls.isEmpty) for (val p <- parents) checkCheckable(pos, p) + else patternWarning(tp, "refinement ") case ThisType(_) => ; case NoPrefix => diff --git a/test/files/pos/bug789.scala b/test/files/pos/bug789.scala new file mode 100644 index 0000000000..7a17f10b0e --- /dev/null +++ b/test/files/pos/bug789.scala @@ -0,0 +1,32 @@ +object main { // don't do this at home + + trait Impl + + trait SizeImpl extends Impl { def size = 42 } + + trait ColorImpl extends Impl { def color = "red" } + + type Both = SizeImpl with ColorImpl + + def info(x:Impl) = x match { + case x:Both => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + def info2(x:Impl) = x match { + case x:SizeImpl with ColorImpl => "size "+x.size+" color "+x.color // you wish + case x:SizeImpl => "size "+x.size + case x:ColorImpl => "color "+x.color + case _ => "n.a." + } + + + def main(args:Array[String]): Unit = { + // make up some class that has a size + class MyNode extends SizeImpl + Console.println("hello " + info(new MyNode)) + Console.println("hello " + info2(new MyNode)) + } +} |