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

Moving string error message to dedicated case class #2740

Merged
merged 1 commit into from
Jun 13, 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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public enum ErrorMessageID {
ValueClassNeedsExactlyOneValParamID,
OnlyCaseClassOrCaseObjectAllowedID,
ExpectedClassOrObjectDefID,
AnonymousFunctionMissingParamTypeID
AnonymousFunctionMissingParamTypeID,
SuperCallsNotAllowedInlineID
;

public int errorNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1608,4 +1608,10 @@ object messages {
val explanation = ""
}

case class SuperCallsNotAllowedInline(symbol: Symbol)(implicit ctx: Context)
extends Message(SuperCallsNotAllowedInlineID) {
val kind = "Syntax"
val msg = s"super call not allowed in inline $symbol"
val explanation = "Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called."
}
}
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import util.Positions._
import Decorators._
import config.Printers.typr
import Symbols._, TypeUtils._
import reporting.diagnostic.messages.SuperCallsNotAllowedInline

/** A macro transform that runs immediately after typer and that performs the following functions:
*
Expand Down Expand Up @@ -182,7 +183,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
transformSelect(paramFwd.adaptRef(fixSignature(tree)), Nil)
case tree: Super =>
if (ctx.owner.enclosingMethod.isInlineMethod)
ctx.error(em"super not allowed in inline ${ctx.owner}", tree.pos)
ctx.error(SuperCallsNotAllowedInline(ctx.owner), tree.pos)
super.transform(tree)
case tree: TypeApply =>
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)
Expand Down
19 changes: 19 additions & 0 deletions compiler/test/dotty/tools/dotc/reporting/ErrorMessagesTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -820,4 +820,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
assertEquals("?", pt.show)
}

@Test def superCallsNotAllowedInline =
checkMessagesAfter("refchecks") {
"""
|class A {
| def foo(): Unit = ()
|}
|
|class B extends A {
| inline def bar(): Unit = super.foo()
|}
""".stripMargin
}
.expect { (ictx, messages) =>
implicit val ctx: Context = ictx
assertMessageCount(1, messages)
val err :: Nil = messages
val SuperCallsNotAllowedInline(symbol) = err
assertEquals("method bar", symbol.show)
}
}