diff options
author | Som Snytt <som.snytt@gmail.com> | 2016-12-07 00:35:02 -0800 |
---|---|---|
committer | Som Snytt <som.snytt@gmail.com> | 2016-12-14 12:34:00 -0800 |
commit | 9df6d16f9b303caa98feb2ccd179352bd646c101 (patch) | |
tree | 09aa2a9be66e7ef89c09956303507293d67711c9 /src/compiler/scala | |
parent | b91b415b4fccfc46520dcd3f128b4b09d19d74f0 (diff) | |
download | scala-9df6d16f9b303caa98feb2ccd179352bd646c101.tar.gz scala-9df6d16f9b303caa98feb2ccd179352bd646c101.tar.bz2 scala-9df6d16f9b303caa98feb2ccd179352bd646c101.zip |
SI-10097 Error if no non-implicit case class param
Case class must have a non-implicit param list.
Error early, error often.
Also update spec to say that class implicitly gets
a non-implicit parameter section if it doesn't
have one, and that a case class must have one.
Diffstat (limited to 'src/compiler/scala')
-rw-r--r-- | src/compiler/scala/tools/nsc/ast/parser/Parsers.scala | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala index cf66e0a7dc..a511d753c1 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/Parsers.scala @@ -2238,6 +2238,8 @@ self => def paramClauses(owner: Name, contextBounds: List[Tree], ofCaseClass: Boolean): List[List[ValDef]] = { var implicitmod = 0 var caseParam = ofCaseClass + val vds = new ListBuffer[List[ValDef]] + val start = in.offset def paramClause(): List[ValDef] = { if (in.token == RPAREN) return Nil @@ -2248,12 +2250,7 @@ self => } commaSeparated(param(owner, implicitmod, caseParam )) } - val vds = new ListBuffer[List[ValDef]] - val start = in.offset newLineOptWhenFollowedBy(LPAREN) - if (ofCaseClass && in.token != LPAREN) - syntaxError(in.lastOffset, "case classes without a parameter list are not allowed;\n"+ - "use either case objects or case classes with an explicit `()' as a parameter list.") while (implicitmod == 0 && in.token == LPAREN) { in.nextToken() vds += paramClause() @@ -2261,6 +2258,14 @@ self => caseParam = false newLineOptWhenFollowedBy(LPAREN) } + if (ofCaseClass) { + if (vds.isEmpty) + syntaxError(in.lastOffset, s"case classes must have a parameter list; try 'case class ${owner.encoded + }()' or 'case object ${owner.encoded}'") + else if (vds.head.nonEmpty && vds.head.head.mods.isImplicit) + syntaxError(in.lastOffset, s"case classes must have a non-implicit parameter list; try 'case class ${ + owner.encoded}()${ vds.map(vs => "(...)").mkString }'") + } val result = vds.toList if (owner == nme.CONSTRUCTOR && (result.isEmpty || (result.head take 1 exists (_.mods.isImplicit)))) { in.token match { |