@@ -1047,6 +1047,30 @@ object RefChecks {
1047
1047
report.error(i " private $sym cannot override ${other.showLocated}" , sym.srcPos)
1048
1048
end checkNoPrivateOverrides
1049
1049
1050
+ /** Check that unary method definition do not receive parameters.
1051
+ * They can only receive inferred parameters such as type parameters and implicit parameters.
1052
+ */
1053
+ def checkUnaryMethods (sym : Symbol )(using Context ): Unit =
1054
+ def checkParameters (tpe : Type ): Unit =
1055
+ tpe match
1056
+ case tpe : MethodType =>
1057
+ if tpe.isImplicitMethod || tpe.isContextualMethod then
1058
+ checkParameters(tpe.resType)
1059
+ else
1060
+ val what =
1061
+ if tpe.paramNames.isEmpty then " empty parameter list.\n\n Possible fix: remove the `()` arguments."
1062
+ else " parameters"
1063
+ report.warning(s " Unary method cannot take $what" , sym.sourcePos)
1064
+ case tpe : PolyType =>
1065
+ checkParameters(tpe.resType)
1066
+ case _ =>
1067
+ // ok
1068
+
1069
+ if sym.name.startsWith(nme.UNARY_PREFIX .toString) then
1070
+ checkParameters(sym.info)
1071
+
1072
+ end checkUnaryMethods
1073
+
1050
1074
type LevelAndIndex = immutable.Map [Symbol , (LevelInfo , Int )]
1051
1075
1052
1076
class OptLevelInfo {
@@ -1254,6 +1278,7 @@ class RefChecks extends MiniPhase { thisPhase =>
1254
1278
checkExperimentalAnnots(tree.symbol)
1255
1279
checkExperimentalSignature(tree.symbol, tree)
1256
1280
checkImplicitNotFoundAnnotation.defDef(tree.symbol.denot)
1281
+ checkUnaryMethods(tree.symbol)
1257
1282
tree
1258
1283
}
1259
1284
0 commit comments