File tree 4 files changed +55
-2
lines changed
test/dotty/tools/dotc/reporting 4 files changed +55
-2
lines changed 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
+ MissingArgumentsForMethodID
110
111
;
111
112
112
113
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1847,4 +1847,35 @@ 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 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 = {
1856
+ 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.
1869
+ |
1870
+ | $codeExample
1871
+ |
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
+ """
1879
+ }
1880
+ }
1850
1881
}
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(MissingEmptyArgumentListForMethod (methPart(tree).symbol, methodStr) , tree.pos)
1912
1912
tree.withType(mt.resultType)
1913
1913
}
1914
1914
Original file line number Diff line number Diff line change @@ -1069,4 +1069,25 @@ class ErrorMessagesTests extends ErrorMessagesTest {
1069
1069
val OnlyFunctionsCanBeFollowedByUnderscore (pt) :: Nil = messages
1070
1070
assertEquals(" String(n)" , pt.show)
1071
1071
}
1072
+
1073
+ @ Test def missingEmptyArgumentListForMethod =
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
+
1089
+ val MissingEmptyArgumentListForMethod (method, _) :: Nil = messages
1090
+
1091
+ assertEquals(" method greet" , method.show)
1092
+ }
1072
1093
}
You can’t perform that action at this time.
0 commit comments