Skip to content

Commit ed05cba

Browse files
authored
Merge pull request #1428 from dotty-staging/fix-#1285
Fix #1285: Mutable vars are not to be considered constant
2 parents 54895cd + 2eb0fed commit ed05cba

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ object Flags {
448448
/** Flags guaranteed to be set upon symbol creation */
449449
final val FromStartFlags =
450450
AccessFlags | Module | Package | Deferred | Final | MethodOrHKCommon | Param | ParamAccessor | Scala2ExistentialCommon |
451-
InSuperCall | Touched | JavaStatic | CovariantOrOuter | ContravariantOrLabel | ExpandedName | AccessorOrSealed |
451+
Mutable.toCommonFlags | InSuperCall | Touched | JavaStatic | CovariantOrOuter | ContravariantOrLabel | ExpandedName | AccessorOrSealed |
452452
CaseAccessorOrBaseTypeArg | Fresh | Frozen | Erroneous | ImplicitCommon | Permanent | Synthetic |
453453
LazyOrTrait | SuperAccessorOrScala2x | SelfNameOrImplClass
454454

src/dotty/tools/dotc/typer/Namer.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -830,8 +830,8 @@ class Namer { typer: Typer =>
830830

831831
// println(s"final inherited for $sym: ${inherited.toString}") !!!
832832
// println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}")
833-
def isInline = sym.is(Final, butNot = Method)
834-
833+
def isInline = sym.is(Final, butNot = Method | Mutable)
834+
835835
// Widen rhs type and approximate `|' but keep ConstantTypes if
836836
// definition is inline (i.e. final in Scala2).
837837
def widenRhs(tp: Type): Type = tp.widenTermRefExpr match {

tests/pos/i1285.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Test {
2+
final var x = false
3+
x = true
4+
}

0 commit comments

Comments
 (0)