Skip to content

Commit 4408cbf

Browse files
committed
Create VolatileOnVal message class
1 parent c7db720 commit 4408cbf

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

compiler/src/dotty/tools/dotc/reporting/ErrorMessageID.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ enum ErrorMessageID(val isActive: Boolean = true) extends java.lang.Enum[ErrorMe
206206
case PureUnitExpressionID // errorNumber: 190
207207
case MatchTypeLegacyPatternID // errorNumber: 191
208208
case UnstableInlineAccessorID // errorNumber: 192
209+
case VolatileOnValID // errorNumber: 193
209210

210211
def errorNumber = ordinal - 1
211212

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3146,3 +3146,8 @@ class UnstableInlineAccessor(accessed: Symbol, accessorTree: tpd.Tree)(using Con
31463146
if accessor.owner.name.isPackageObjectName then accessor.owner.owner.name.stripModuleClassSuffix
31473147
else accessor.owner.name.stripModuleClassSuffix
31483148
}
3149+
3150+
class VolatileOnVal()(using Context)
3151+
extends SyntaxMsg(VolatileOnValID):
3152+
protected def msg(using Context): String = "values cannot be volatile"
3153+
protected def explain(using Context): String = ""

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,8 @@ object RefChecks {
10031003

10041004
def checkVolatile(sym: Symbol)(using Context): Unit =
10051005
if sym.isVolatile && !sym.is(Mutable) then
1006-
report.warning(em"values cannot be volatile", sym.srcPos)
1006+
report.warning(VolatileOnVal(), sym.srcPos)
1007+
10071008
/** Check that unary method definition do not receive parameters.
10081009
* They can only receive inferred parameters such as type parameters and implicit parameters.
10091010
*/

0 commit comments

Comments
 (0)