File tree 4 files changed +37
-1
lines changed
test/dotty/tools/dotc/reporting
4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ public enum ErrorMessageID {
92
92
SuperCallsNotAllowedInlineID ,
93
93
ModifiersNotAllowedID ,
94
94
WildcardOnTypeArgumentNotAllowedOnNewID ,
95
+ ImplicitFunctionTypeNeedsNonEmptyParameterListID ,
95
96
;
96
97
97
98
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1668,4 +1668,23 @@ object messages {
1668
1668
"""
1669
1669
}
1670
1670
}
1671
+
1672
+ case class ImplicitFunctionTypeNeedsNonEmptyParameterList ()(implicit ctx : Context )
1673
+ extends Message (ImplicitFunctionTypeNeedsNonEmptyParameterListID ) {
1674
+ val kind = " Syntax"
1675
+ val msg = " implicit function type needs non-empty parameter list"
1676
+ val explanation = {
1677
+ val code1 = " type Transactional[T] = implicit Transaction => T"
1678
+ val code2 = " val cl: implicit A => B"
1679
+ hl """ It is not allowed to leave implicit function parameter list empty.
1680
+ |Possible ways to define implicit function type:
1681
+ |
1682
+ | $code1
1683
+ |
1684
+ |or
1685
+ |
1686
+ | $code2""" .stripMargin
1687
+ }
1688
+ }
1689
+
1671
1690
}
Original file line number Diff line number Diff line change @@ -690,7 +690,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
690
690
val isImplicit = tree match {
691
691
case _ : untpd.ImplicitFunction =>
692
692
if (args.length == 0 ) {
693
- ctx.error(i " implicit function type needs non-empty parameter list " , tree.pos)
693
+ ctx.error(ImplicitFunctionTypeNeedsNonEmptyParameterList () , tree.pos)
694
694
false
695
695
}
696
696
else true
Original file line number Diff line number Diff line change @@ -877,4 +877,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
877
877
878
878
assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew ())
879
879
}
880
+
881
+ @ Test def implicitFunctionTypeNeedsNonEmptyParameterList =
882
+ checkMessagesAfter(" refchecks" ) {
883
+ """ abstract class Foo {
884
+ | type Contextual[T] = implicit () => T
885
+ | val x: implicit () => Int
886
+ |}""" .stripMargin
887
+ }
888
+ .expect { (ictx, messages) =>
889
+ implicit val ctx : Context = ictx
890
+ val defn = ictx.definitions
891
+
892
+ assertMessageCount(2 , messages)
893
+ messages.foreach(assertEquals(_, ImplicitFunctionTypeNeedsNonEmptyParameterList ()))
894
+ }
895
+
880
896
}
You can’t perform that action at this time.
0 commit comments