File tree Expand file tree Collapse file tree 4 files changed +30
-2
lines changed
test/dotty/tools/dotc/reporting Expand file tree Collapse file tree 4 files changed +30
-2
lines changed Original file line number Diff line number Diff line change @@ -1681,7 +1681,7 @@ object Parsers {
16811681
16821682 def addFlag (mods : Modifiers , flag : FlagSet ): Modifiers = {
16831683 def incompatible (kind : String ) = {
1684- syntaxError(s " modifier(s) ` ${ mods.flags} ' not allowed for $ kind" )
1684+ syntaxError(ModifiersNotAllowed ( mods.flags, kind) )
16851685 Modifiers (flag)
16861686 }
16871687 if (compatible(mods.flags, flag)) mods | flag
Original file line number Diff line number Diff line change @@ -89,7 +89,8 @@ public enum ErrorMessageID {
8989 OnlyCaseClassOrCaseObjectAllowedID ,
9090 ExpectedClassOrObjectDefID ,
9191 AnonymousFunctionMissingParamTypeID ,
92- SuperCallsNotAllowedInlineID
92+ SuperCallsNotAllowedInlineID ,
93+ ModifiersNotAllowedID ,
9394 ;
9495
9596 public int errorNumber () {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import printing.Formatting
2020import ErrorMessageID ._
2121import Denotations .SingleDenotation
2222import dotty .tools .dotc .ast .Trees
23+ import dotty .tools .dotc .ast .untpd .Modifiers
2324import dotty .tools .dotc .core .Flags .{FlagSet , Mutable }
2425import dotty .tools .dotc .core .SymDenotations .SymDenotation
2526
@@ -1614,4 +1615,20 @@ object messages {
16141615 val msg = s " super call not allowed in inline $symbol"
16151616 val explanation = " Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called."
16161617 }
1618+
1619+ case class ModifiersNotAllowed (flags : FlagSet , sort : String )(implicit ctx : Context )
1620+ extends Message (ModifiersNotAllowedID ) {
1621+ val kind = " Syntax"
1622+ val msg = s " modifier(s) ` $flags' not allowed for $sort"
1623+ val explanation = {
1624+ val code = " sealed def y: Int = 1"
1625+ hl """ You tried to use a modifier that is inapplicable for the type of item under modification
1626+ |
1627+ |
1628+ |Consider the following example:
1629+ | $code
1630+ |In this instance, the modifier 'sealed' is not applicable to the item type 'def' (method)
1631+ """
1632+ }
1633+ }
16171634}
Original file line number Diff line number Diff line change @@ -839,4 +839,14 @@ class ErrorMessagesTests extends ErrorMessagesTest {
839839 val SuperCallsNotAllowedInline (symbol) = err
840840 assertEquals(" method bar" , symbol.show)
841841 }
842+
843+ @ Test def modifiersNotAllowed =
844+ checkMessagesAfter(" refchecks" )(""" lazy trait T""" )
845+ .expect { (ictx, messages) =>
846+ implicit val ctx : Context = ictx
847+ assertMessageCount(1 , messages)
848+ val ModifiersNotAllowed (flags, sort) :: Nil = messages
849+ assertEquals(" lazy" , flags.toString)
850+ assertEquals(" trait" , sort)
851+ }
842852}
You can’t perform that action at this time.
0 commit comments