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 @@ -1668,4 +1668,23 @@ object messages {
16681668 """
16691669 }
16701670 }
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+
16711690}
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 @@ -877,4 +877,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {
877877
878878 assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew ())
879879 }
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+
880896}
You can’t perform that action at this time.
0 commit comments