File tree Expand file tree Collapse file tree 4 files changed +37
-1
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ public enum ErrorMessageID {
9292 SuperCallsNotAllowedInlineID ,
9393 ModifiersNotAllowedID ,
9494 WildcardOnTypeArgumentNotAllowedOnNewID ,
95+ ImplicitFunctionTypeNeedsNonEmptyParameterListID ,
9596 ;
9697
9798 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1663,4 +1663,23 @@ object messages {
16631663 """
16641664 }
16651665 }
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+
16661685}
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
690690 val isImplicit = tree match {
691691 case _ : untpd.ImplicitFunction =>
692692 if (args.length == 0 ) {
693- ctx.error(i " implicit function type needs non-empty parameter list " , tree.pos)
693+ ctx.error(ImplicitFunctionTypeNeedsNonEmptyParameterList () , tree.pos)
694694 false
695695 }
696696 else true
Original file line number Diff line number Diff line change @@ -867,4 +867,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
867867
868868 assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew ())
869869 }
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+
870886}
You can’t perform that action at this time.
0 commit comments