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 {
1681
1681
1682
1682
def addFlag (mods : Modifiers , flag : FlagSet ): Modifiers = {
1683
1683
def incompatible (kind : String ) = {
1684
- syntaxError(s " modifier(s) ` ${ mods.flags} ' not allowed for $ kind" )
1684
+ syntaxError(ModifiersNotAllowed ( mods.flags, kind) )
1685
1685
Modifiers (flag)
1686
1686
}
1687
1687
if (compatible(mods.flags, flag)) mods | flag
Original file line number Diff line number Diff line change @@ -89,7 +89,8 @@ public enum ErrorMessageID {
89
89
OnlyCaseClassOrCaseObjectAllowedID ,
90
90
ExpectedClassOrObjectDefID ,
91
91
AnonymousFunctionMissingParamTypeID ,
92
- SuperCallsNotAllowedInlineID
92
+ SuperCallsNotAllowedInlineID ,
93
+ ModifiersNotAllowedID ,
93
94
;
94
95
95
96
public int errorNumber () {
Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ import printing.Formatting
20
20
import ErrorMessageID ._
21
21
import Denotations .SingleDenotation
22
22
import dotty .tools .dotc .ast .Trees
23
+ import dotty .tools .dotc .ast .untpd .Modifiers
23
24
import dotty .tools .dotc .core .Flags .{FlagSet , Mutable }
24
25
import dotty .tools .dotc .core .SymDenotations .SymDenotation
25
26
@@ -1614,4 +1615,20 @@ object messages {
1614
1615
val msg = s " super call not allowed in inline $symbol"
1615
1616
val explanation = " Method inlining prohibits calling superclass methods, as it may lead to confusion about which super is being called."
1616
1617
}
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
+ }
1617
1634
}
Original file line number Diff line number Diff line change @@ -839,4 +839,14 @@ class ErrorMessagesTests extends ErrorMessagesTest {
839
839
val SuperCallsNotAllowedInline (symbol) = err
840
840
assertEquals(" method bar" , symbol.show)
841
841
}
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
+ }
842
852
}
You can’t perform that action at this time.
0 commit comments