Skip to content

Commit c9e2e6a

Browse files
authored
Merge pull request #2740 from msosnicki/super-calls-not-allowed-inline
Moving string error message to dedicated case class
2 parents cee829f + 6c3e5a2 commit c9e2e6a

File tree

4 files changed

+29
-2
lines changed

4 files changed

+29
-2
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,8 @@ public enum ErrorMessageID {
8888
ValueClassNeedsExactlyOneValParamID,
8989
OnlyCaseClassOrCaseObjectAllowedID,
9090
ExpectedClassOrObjectDefID,
91-
AnonymousFunctionMissingParamTypeID
91+
AnonymousFunctionMissingParamTypeID,
92+
SuperCallsNotAllowedInlineID
9293
;
9394

9495
public int errorNumber() {

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,4 +1608,10 @@ object messages {
16081608
val explanation = ""
16091609
}
16101610

1611+
case class SuperCallsNotAllowedInline(symbol: Symbol)(implicit ctx: Context)
1612+
extends Message(SuperCallsNotAllowedInlineID) {
1613+
val kind = "Syntax"
1614+
val msg = s"super call not allowed in inline $symbol"
1615+
val explanation = "Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called."
1616+
}
16111617
}

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import util.Positions._
1515
import Decorators._
1616
import config.Printers.typr
1717
import Symbols._, TypeUtils._
18+
import reporting.diagnostic.messages.SuperCallsNotAllowedInline
1819

1920
/** A macro transform that runs immediately after typer and that performs the following functions:
2021
*
@@ -182,7 +183,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
182183
transformSelect(paramFwd.adaptRef(fixSignature(tree)), Nil)
183184
case tree: Super =>
184185
if (ctx.owner.enclosingMethod.isInlineMethod)
185-
ctx.error(em"super not allowed in inline ${ctx.owner}", tree.pos)
186+
ctx.error(SuperCallsNotAllowedInline(ctx.owner), tree.pos)
186187
super.transform(tree)
187188
case tree: TypeApply =>
188189
val tree1 @ TypeApply(fn, args) = normalizeTypeArgs(tree)

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,4 +820,23 @@ class ErrorMessagesTests extends ErrorMessagesTest {
820820
assertEquals("?", pt.show)
821821
}
822822

823+
@Test def superCallsNotAllowedInline =
824+
checkMessagesAfter("refchecks") {
825+
"""
826+
|class A {
827+
| def foo(): Unit = ()
828+
|}
829+
|
830+
|class B extends A {
831+
| inline def bar(): Unit = super.foo()
832+
|}
833+
""".stripMargin
834+
}
835+
.expect { (ictx, messages) =>
836+
implicit val ctx: Context = ictx
837+
assertMessageCount(1, messages)
838+
val err :: Nil = messages
839+
val SuperCallsNotAllowedInline(symbol) = err
840+
assertEquals("method bar", symbol.show)
841+
}
823842
}

0 commit comments

Comments
 (0)