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 @@ -1663,4 +1663,23 @@ object messages {
1663
1663
"""
1664
1664
}
1665
1665
}
1666
+
1667
+ case class ImplicitFunctionTypeNeedsNonEmptyParameterList ()(implicit ctx : Context )
1668
+ extends Message (ImplicitFunctionTypeNeedsNonEmptyParameterListID ) {
1669
+ val kind = " Syntax"
1670
+ val msg = " implicit function type needs non-empty parameter list"
1671
+ val explanation = {
1672
+ val code1 = " type Transactional[T] = implicit Transaction => T"
1673
+ val code2 = " val cl: implicit A => B"
1674
+ hl """ It is not allowed to leave implicit function parameter list empty.
1675
+ |Possible ways to define implicit function type:
1676
+ |
1677
+ | $code1
1678
+ |
1679
+ |or
1680
+ |
1681
+ | $code2""" .stripMargin
1682
+ }
1683
+ }
1684
+
1666
1685
}
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 @@ -867,4 +867,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
867
867
868
868
assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew ())
869
869
}
870
+
871
+ @ Test def implicitFunctionTypeNeedsNonEmptyParameterList =
872
+ checkMessagesAfter(" refchecks" ) {
873
+ """ abstract class Foo {
874
+ | type Contextual[T] = implicit () => T
875
+ | val x: implicit () => Int
876
+ |}""" .stripMargin
877
+ }
878
+ .expect { (ictx, messages) =>
879
+ implicit val ctx : Context = ictx
880
+ val defn = ictx.definitions
881
+
882
+ assertMessageCount(2 , messages)
883
+ messages.foreach(assertEquals(_, ImplicitFunctionTypeNeedsNonEmptyParameterList ()))
884
+ }
885
+
870
886
}
You can’t perform that action at this time.
0 commit comments