Skip to content

Commit 0af2bd8

Browse files
committed
Polishing
1 parent b83a7f0 commit 0af2bd8

File tree

5 files changed

+18
-32
lines changed

5 files changed

+18
-32
lines changed

compiler/src/dotty/tools/dotc/core/TypeOps.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import util.Property
1717
import collection.mutable
1818
import ast.tpd._
1919
import reporting.trace
20+
import reporting.diagnostic.Message
2021

2122
trait TypeOps { this: Context => // TODO: Make standalone object.
2223

@@ -315,7 +316,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
315316
def dynamicsEnabled =
316317
featureEnabled(defn.LanguageModuleClass, nme.dynamics)
317318

318-
def testScala2Mode(msg: => String, pos: Position, rewrite: => Unit = ()) = {
319+
def testScala2Mode(msg: => Message, pos: Position, rewrite: => Unit = ()) = {
319320
if (scala2Mode) {
320321
migrationWarning(msg, pos)
321322
rewrite

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public enum ErrorMessageID {
107107
TailrecNotApplicableID,
108108
FailureToEliminateExistentialID,
109109
OnlyFunctionsCanBeFollowedByUnderscoreID,
110-
MissingArgumentsForMethodID
110+
MissingEmptyArgumentListID
111111
;
112112

113113
public int errorNumber() {

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

Lines changed: 11 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1848,34 +1848,21 @@ object messages {
18481848
|To convert to a function value, you need to explicitly write ${"() => x"}"""
18491849
}
18501850

1851-
case class MissingEmptyArgumentListForMethod(method: Symbol, methodStr: String)(implicit ctx: Context)
1852-
extends Message(MissingArgumentsForMethodID) {
1853-
val kind: String = "Syntax"
1854-
val msg: String = hl"$methodStr must be called with an empty argument list"
1855-
val explanation: String = {
1851+
case class MissingEmptyArgumentList(method: Symbol)(implicit ctx: Context)
1852+
extends Message(MissingEmptyArgumentListID) {
1853+
val kind = "Syntax"
1854+
val msg = hl"$method must be called with ${"()"} argument"
1855+
val explanation = {
18561856
val codeExample =
1857-
"""
1858-
|def next(): T = ...
1859-
|next // is expanded to next()
1860-
"""
1861-
val errorMessage =
1862-
"""
1863-
|next
1864-
|^^^^
1865-
|method next must be called with an empty argument list
1866-
"""
1867-
hl"""
1868-
|Previously an empty argument list () was implicitly inserted when calling a nullary method without arguments. E.g.
1857+
"""def next(): T = ...
1858+
|next // is expanded to next()"""
1859+
1860+
hl"""Previously an empty argument list () was implicitly inserted when calling a nullary method without arguments. E.g.
18691861
|
18701862
|$codeExample
18711863
|
1872-
|In Dotty, this idiom is an error which leads to the following message:
1873-
|
1874-
|$errorMessage
1875-
|
1876-
|In Dotty, the application syntax has to follow exactly the parameter syntax.
1877-
|Excluded from this rule are methods that are defined in Java or that override methods defined in Java.
1878-
"""
1864+
|In Dotty, this idiom is an error. The application syntax has to follow exactly the parameter syntax.
1865+
|Excluded from this rule are methods that are defined in Java or that override methods defined in Java."""
18791866
}
18801867
}
18811868
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
19081908
def methodStr = err.refStr(methPart(tree).tpe)
19091909

19101910
def missingArgs(mt: MethodType) = {
1911-
ctx.error(MissingEmptyArgumentListForMethod(methPart(tree).symbol, methodStr), tree.pos)
1911+
ctx.error(MissingEmptyArgumentList(methPart(tree).symbol), tree.pos)
19121912
tree.withType(mt.resultType)
19131913
}
19141914

@@ -2076,7 +2076,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
20762076
def isAutoApplied(sym: Symbol): Boolean = {
20772077
sym.isConstructor ||
20782078
sym.matchNullaryLoosely ||
2079-
ctx.testScala2Mode(em"${sym.showLocated} requires () argument", tree.pos,
2079+
ctx.testScala2Mode(MissingEmptyArgumentList(sym), tree.pos,
20802080
patch(tree.pos.endPos, "()"))
20812081
}
20822082

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1070,7 +1070,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
10701070
assertEquals("String(n)", pt.show)
10711071
}
10721072

1073-
@Test def missingEmptyArgumentListForMethod =
1073+
@Test def missingEmptyArgumentList =
10741074
checkMessagesAfter("frontend") {
10751075
"""
10761076
|class Test {
@@ -1085,9 +1085,7 @@ class ErrorMessagesTests extends ErrorMessagesTest {
10851085
implicit val ctx: Context = ictx
10861086

10871087
assertMessageCount(1, messages)
1088-
1089-
val MissingEmptyArgumentListForMethod(method, _) :: Nil = messages
1090-
1088+
val MissingEmptyArgumentList(method) :: Nil = messages
10911089
assertEquals("method greet", method.show)
10921090
}
10931091
}

0 commit comments

Comments
 (0)