From 51e4a6a351a64a1bff995e1b5fefb88c7e2430eb Mon Sep 17 00:00:00 2001 From: Paul Phillips Date: Tue, 30 Nov 2010 17:57:15 +0000 Subject: Parser relaxation so that one can name the type... Parser relaxation so that one can name the type variables in a constructor pattern match: this is a prerequisite to realizing the full potential of gadts. (Nothing new works here however.) No review. --- .../scala/tools/nsc/ast/parser/Parsers.scala | 21 ++++++++------------- test/files/neg/gadts1.check | 10 +++++++++- test/files/neg/gadts1.scala | 8 +++++++- 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index 09f1db7249..1ae9a9d8c0 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -1633,19 +1633,14 @@ self => } case _ => } - /* not yet - if (in.token == LBRACKET) - atPos(in.offset) { - val ts = typeArgs(true, false) - accept(LPAREN) - val ps = if (in.token == RPAREN) List() else patterns(true, false) - accept(RPAREN) - Apply(TypeApply(convertToTypeId(t), ts), ps) - } - else */ - if (in.token == LPAREN) - atPos(start, in.offset) { Apply(t, argumentPatterns()) } - else t + val typeAppliedTree = in.token match { + case LBRACKET => atPos(start, in.offset)(TypeApply(convertToTypeId(t), typeArgs(true, false))) + case _ => t + } + in.token match { + case LPAREN => atPos(start, in.offset)(Apply(typeAppliedTree, argumentPatterns())) + case _ => typeAppliedTree + } case USCORE => in.nextToken() atPos(start, start) { Ident(nme.WILDCARD) } diff --git a/test/files/neg/gadts1.check b/test/files/neg/gadts1.check index 4c91a3bcf8..44d2b114d6 100644 --- a/test/files/neg/gadts1.check +++ b/test/files/neg/gadts1.check @@ -3,4 +3,12 @@ gadts1.scala:15: error: type mismatch; required: a case NumTerm(n) => c.x = Double(1.0) ^ -one error found +gadts1.scala:20: error: class Cell of type Test.Cell does not take type parameters. + case Cell[a](x: Int) => c.x = 5 + ^ +gadts1.scala:20: error: type mismatch; + found : Int(5) + required: a + case Cell[a](x: Int) => c.x = 5 + ^ +three errors found diff --git a/test/files/neg/gadts1.scala b/test/files/neg/gadts1.scala index 07200ff7aa..08403e6eec 100644 --- a/test/files/neg/gadts1.scala +++ b/test/files/neg/gadts1.scala @@ -10,10 +10,16 @@ case class NumTerm(val n: Number) extends Term[Number] class IntTerm(n: Int) extends NumTerm(n) with Term[Int] -def f[a](t:Term[a], c:Cell[a]): Unit = +def f[a](t:Term[a], c:Cell[a]): Unit = { t match { case NumTerm(n) => c.x = Double(1.0) } + t match { + // presently testing that this gets past the parser: eventually + // it should actually work. + case Cell[a](x: Int) => c.x = 5 + } +} val x:Term[Number] = NumTerm(Int(5)) -- cgit v1.2.3