Skip to content

Commit 7bc8411

Browse files
miklaamiklushou
authored andcommitted
Refs #1589 Move "implicit function type needs non-empty parameter list" error to a new errors format.
1 parent bf1082d commit 7bc8411

File tree

4 files changed

+37
-1
lines changed

4 files changed

+37
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/diagnostic/ErrorMessageID.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public enum ErrorMessageID {
9292
SuperCallsNotAllowedInlineID,
9393
ModifiersNotAllowedID,
9494
WildcardOnTypeArgumentNotAllowedOnNewID,
95+
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
9596
;
9697

9798
public int errorNumber() {

compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff 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

compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)