File tree Expand file tree Collapse file tree 4 files changed +29
-2
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +29
-2
lines changed Original file line number Diff line number Diff 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 () {
Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import util.Positions._
1515import Decorators ._
1616import config .Printers .typr
1717import 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)
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments