File tree 4 files changed +29
-2
lines changed
test/dotty/tools/dotc/reporting 4 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -88,7 +88,8 @@ public enum ErrorMessageID {
88
88
ValueClassNeedsExactlyOneValParamID ,
89
89
OnlyCaseClassOrCaseObjectAllowedID ,
90
90
ExpectedClassOrObjectDefID ,
91
- AnonymousFunctionMissingParamTypeID
91
+ AnonymousFunctionMissingParamTypeID ,
92
+ SuperCallsNotAllowedInlineID
92
93
;
93
94
94
95
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -1608,4 +1608,10 @@ object messages {
1608
1608
val explanation = " "
1609
1609
}
1610
1610
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
+ }
1611
1617
}
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ import util.Positions._
15
15
import Decorators ._
16
16
import config .Printers .typr
17
17
import Symbols ._ , TypeUtils ._
18
+ import reporting .diagnostic .messages .SuperCallsNotAllowedInline
18
19
19
20
/** A macro transform that runs immediately after typer and that performs the following functions:
20
21
*
@@ -182,7 +183,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisTran
182
183
transformSelect(paramFwd.adaptRef(fixSignature(tree)), Nil )
183
184
case tree : Super =>
184
185
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)
186
187
super .transform(tree)
187
188
case tree : TypeApply =>
188
189
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 {
820
820
assertEquals(" ?" , pt.show)
821
821
}
822
822
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
+ }
823
842
}
You can’t perform that action at this time.
0 commit comments