Skip to content

Commit 6fec962

Browse files
committed
Update error msg for Parsers.scala:1738 and 1739
These error messages are for aux ctors needing non-implicit params. I'm testing the error messages with this code ``` class Square(val len: Int) { // typical cases: // (1) this() parens are forgotten, (2) argument set as implicit def this(implicit width: Double) = this(0) def this = { this(4) } } class MyList(val s: String) { def this ```
1 parent aae4019 commit 6fec962

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,8 +1742,8 @@ object Parsers {
17421742
if (owner == nme.CONSTRUCTOR && (result.isEmpty || (result.head take 1 exists (_.mods is Implicit)))) {
17431743
in.token match {
17441744
case LBRACKET => syntaxError("no type parameters allowed here")
1745-
case EOF => incompleteInputError("auxiliary constructor needs non-implicit parameter list")
1746-
case _ => syntaxError("auxiliary constructor needs non-implicit parameter list", start)
1745+
case EOF => incompleteInputError(AuxConstructorNeedsNonImplicitParameter())
1746+
case _ => syntaxError(AuxConstructorNeedsNonImplicitParameter(), start)
17471747
}
17481748
}
17491749
result

src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,4 +678,22 @@ object messages {
678678
|$fixedVarInAlternative""".stripMargin
679679
}
680680
}
681+
682+
case class AuxConstructorNeedsNonImplicitParameter()(implicit ctx:Context) extends Message(24) {
683+
val kind = "Syntax"
684+
val msg = "auxiliary constructor needs non-implicit parameter list"
685+
val explanation =
686+
hl"""An auxiliary constructor requires a non-implicit parameter list. Auxiliary
687+
|constructors are allowed to call either auxiliary or primary constructors,
688+
|where the primary constructor is allowed implicit parameters. A common mistake
689+
|is to forget the parenthesis on `this` (eg `def this() = ...`).
690+
|
691+
|Here's an example class with primary and auxiliary constructors:
692+
|
693+
|class Person(val first: String, val last: String) {
694+
| def this() = this("John", "Doe")
695+
| def this(last: String) = this("John", last)
696+
|}""".stripMargin
697+
}
698+
681699
}

0 commit comments

Comments
 (0)