Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1589 Move "implicit function type needs non-empty parameter list" error to a new errors format. #2821

Merged
merged 1 commit into from Jun 30, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -92,6 +92,7 @@ public enum ErrorMessageID {
SuperCallsNotAllowedInlineID,
ModifiersNotAllowedID,
WildcardOnTypeArgumentNotAllowedOnNewID,
ImplicitFunctionTypeNeedsNonEmptyParameterListID,
;

public int errorNumber() {
Expand Down
19 changes: 19 additions & 0 deletions compiler/src/dotty/tools/dotc/reporting/diagnostic/messages.scala
Expand Up @@ -1663,4 +1663,23 @@ object messages {
"""
}
}

case class ImplicitFunctionTypeNeedsNonEmptyParameterList()(implicit ctx: Context)
extends Message(ImplicitFunctionTypeNeedsNonEmptyParameterListID) {
val kind = "Syntax"
val msg = "implicit function type needs non-empty parameter list"
val explanation = {
val code1 = "type Transactional[T] = implicit Transaction => T"
val code2 = "val cl: implicit A => B"
hl"""It is not allowed to leave implicit function parameter list empty.
|Possible ways to define implicit function type:
|
|$code1
|
|or
|
|$code2""".stripMargin
}
}

}
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/typer/Typer.scala
Expand Up @@ -690,7 +690,7 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
val isImplicit = tree match {
case _: untpd.ImplicitFunction =>
if (args.length == 0) {
ctx.error(i"implicit function type needs non-empty parameter list", tree.pos)
ctx.error(ImplicitFunctionTypeNeedsNonEmptyParameterList(), tree.pos)
false
}
else true
Expand Down
16 changes: 16 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Expand Up @@ -867,4 +867,20 @@ class ErrorMessagesTests extends ErrorMessagesTest {

assertEquals(err, WildcardOnTypeArgumentNotAllowedOnNew())
}

@Test def implicitFunctionTypeNeedsNonEmptyParameterList =
checkMessagesAfter("refchecks") {
"""abstract class Foo {
| type Contextual[T] = implicit () => T
| val x: implicit () => Int
|}""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
val defn = ictx.definitions

assertMessageCount(2, messages)
messages.foreach(assertEquals(_, ImplicitFunctionTypeNeedsNonEmptyParameterList()))
}

}