Skip to content

Commit ebb609b

Browse files
committed
Make instance defs final
1 parent 6f5df94 commit ebb609b

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -685,7 +685,7 @@ object desugar {
685685
// implicit wrapper is typechecked in same scope as constructor, so
686686
// we can reuse the constructor parameters; no derived params are needed.
687687
DefDef(className.toTermName, constrTparams, defParamss, classTypeRef, creatorExpr)
688-
.withMods(companionMods | Synthetic | Implicit)
688+
.withMods(companionMods | Synthetic | Implicit | Final)
689689
.withSpan(cdef.span) :: Nil
690690
}
691691

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

+3-1
Original file line numberDiff line numberDiff line change
@@ -2559,6 +2559,7 @@ object Parsers {
25592559
* | ‘of’ Type ‘=’ Expr
25602560
*/
25612561
def instanceDef(start: Offset, mods: Modifiers, instanceMod: Mod) = atSpan(start, nameStart) {
2562+
var mods1 = addMod(mods, instanceMod)
25622563
val name = if (isIdent && !isIdent(nme.of)) ident() else EmptyTermName
25632564
val tparams = typeParamClauseOpt(ParamOwner.Def)
25642565
val vparamss = paramClauses(ofInstance = true)
@@ -2571,6 +2572,7 @@ object Parsers {
25712572
val instDef =
25722573
if (in.token == EQUALS && parents.length == 1 && parents.head.isType) {
25732574
in.nextToken()
2575+
mods1 |= Final
25742576
DefDef(name, tparams, vparamss, parents.head, expr())
25752577
}
25762578
else {
@@ -2582,7 +2584,7 @@ object Parsers {
25822584
if (tparams.isEmpty && vparamss.isEmpty) ModuleDef(name, templ)
25832585
else TypeDef(name.toTypeName, templ)
25842586
}
2585-
finalizeDef(instDef, addMod(mods, instanceMod), start)
2587+
finalizeDef(instDef, mods1, start)
25862588
}
25872589

25882590
/* -------- TEMPLATES ------------------------------------------- */

0 commit comments

Comments
 (0)