File tree 5 files changed +43
-4
lines changed
test/dotty/tools/dotc/reporting
5 files changed +43
-4
lines changed Original file line number Diff line number Diff line change @@ -17,6 +17,7 @@ import util.Property
17
17
import collection .mutable
18
18
import ast .tpd ._
19
19
import reporting .trace
20
+ import reporting .diagnostic .Message
20
21
21
22
trait TypeOps { this : Context => // TODO: Make standalone object.
22
23
@@ -315,7 +316,7 @@ trait TypeOps { this: Context => // TODO: Make standalone object.
315
316
def dynamicsEnabled =
316
317
featureEnabled(defn.LanguageModuleClass , nme.dynamics)
317
318
318
- def testScala2Mode (msg : => String , pos : Position , rewrite : => Unit = ()) = {
319
+ def testScala2Mode (msg : => Message , pos : Position , rewrite : => Unit = ()) = {
319
320
if (scala2Mode) {
320
321
migrationWarning(msg, pos)
321
322
rewrite
Original file line number Diff line number Diff line change @@ -106,7 +106,8 @@ public enum ErrorMessageID {
106
106
ClassAndCompanionNameClashID ,
107
107
TailrecNotApplicableID ,
108
108
FailureToEliminateExistentialID ,
109
- OnlyFunctionsCanBeFollowedByUnderscoreID
109
+ OnlyFunctionsCanBeFollowedByUnderscoreID ,
110
+ MissingEmptyArgumentListID
110
111
;
111
112
112
113
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1847,4 +1847,22 @@ object messages {
1847
1847
hl """ The syntax ${" x _" } is no longer supported if ${" x" } is not a function.
1848
1848
|To convert to a function value, you need to explicitly write ${" () => x" }"""
1849
1849
}
1850
+
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 = {
1856
+ val codeExample =
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.
1861
+ |
1862
+ | $codeExample
1863
+ |
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. """
1866
+ }
1867
+ }
1850
1868
}
Original file line number Diff line number Diff line change @@ -1908,7 +1908,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
1908
1908
def methodStr = err.refStr(methPart(tree).tpe)
1909
1909
1910
1910
def missingArgs (mt : MethodType ) = {
1911
- ctx.error(em " missing arguments for $methodStr " , tree.pos)
1911
+ ctx.error(MissingEmptyArgumentList (methPart(tree).symbol) , tree.pos)
1912
1912
tree.withType(mt.resultType)
1913
1913
}
1914
1914
@@ -2076,7 +2076,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
2076
2076
def isAutoApplied (sym : Symbol ): Boolean = {
2077
2077
sym.isConstructor ||
2078
2078
sym.matchNullaryLoosely ||
2079
- ctx.testScala2Mode(em " ${sym.showLocated} requires () argument " , tree.pos,
2079
+ ctx.testScala2Mode(MissingEmptyArgumentList (sym) , tree.pos,
2080
2080
patch(tree.pos.endPos, " ()" ))
2081
2081
}
2082
2082
Original file line number Diff line number Diff line change @@ -1069,4 +1069,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1069
1069
val OnlyFunctionsCanBeFollowedByUnderscore (pt) :: Nil = messages
1070
1070
assertEquals(" String(n)" , pt.show)
1071
1071
}
1072
+
1073
+ @ Test def missingEmptyArgumentList =
1074
+ checkMessagesAfter(" frontend" ) {
1075
+ """
1076
+ |class Test {
1077
+ | def greet(): String = "Hello"
1078
+ | def main(args: Array[String]): Unit = {
1079
+ | greet
1080
+ | }
1081
+ |}
1082
+ """ .stripMargin
1083
+ }
1084
+ .expect { (ictx, messages) =>
1085
+ implicit val ctx : Context = ictx
1086
+
1087
+ assertMessageCount(1 , messages)
1088
+ val MissingEmptyArgumentList (method) :: Nil = messages
1089
+ assertEquals(" method greet" , method.show)
1090
+ }
1072
1091
}
You can’t perform that action at this time.
0 commit comments