Skip to content

Commit 3bfe849

Browse files
authored
Merge pull request #2821 from mikla/implicit-function-error-message
#1589 Move "implicit function type needs non-empty parameter list" error to a new errors format.
2 parents 425c8c1 + 7bc8411 commit 3bfe849

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

+1
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

+19
Original file line numberDiff line numberDiff 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
}

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

+1-1
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

+16
Original file line numberDiff line numberDiff 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
}

0 commit comments

Comments
 (0)