@@ -151,12 +151,12 @@ class Objects(using Context @constructorOnly):
151
151
def hasVar (sym : Symbol )(using Heap .MutableData ): Boolean = Heap .containsVal(this , sym)
152
152
153
153
def initVal (field : Symbol , value : Value )(using Context , Heap .MutableData ) = log(" Initialize " + field.show + " = " + value + " for " + this , printer) {
154
- assert(! field.is(Flags .Mutable ), " Field is mutable: " + field.show)
154
+ assert(field.is( Flags . Param ) || ! field.is(Flags .Mutable ), " Field is mutable: " + field.show)
155
155
Heap .writeJoinVal(this , field, value)
156
156
}
157
157
158
158
def initVar (field : Symbol , value : Value )(using Context , Heap .MutableData ) = log(" Initialize " + field.show + " = " + value + " for " + this , printer) {
159
- assert(field.is(Flags .Mutable ), " Field is not mutable: " + field.show)
159
+ assert(field.is(Flags .Mutable , butNot = Flags . Param ), " Field is not mutable: " + field.show)
160
160
Heap .writeJoinVal(this , field, value)
161
161
}
162
162
@@ -421,12 +421,12 @@ class Objects(using Context @constructorOnly):
421
421
def hasVar (sym : Symbol )(using EnvMap .EnvMapMutableData ): Boolean = EnvMap .containsVal(this , sym)
422
422
423
423
def initVal (field : Symbol , value : Value )(using Context , EnvMap .EnvMapMutableData ) = log(" Initialize " + field.show + " = " + value + " for " + this , printer) {
424
- assert(! field.is(Flags .Mutable ), " Field is mutable: " + field.show)
424
+ assert(field.is( Flags . Param ) || ! field.is(Flags .Mutable ), " Field is mutable: " + field.show)
425
425
EnvMap .writeJoinVal(this , field, value)
426
426
}
427
427
428
428
def initVar (field : Symbol , value : Value )(using Context , EnvMap .EnvMapMutableData ) = log(" Initialize " + field.show + " = " + value + " for " + this , printer) {
429
- assert(field.is(Flags .Mutable ), " Field is not mutable: " + field.show)
429
+ assert(field.is(Flags .Mutable , butNot = Flags . Param ), " Field is not mutable: " + field.show)
430
430
EnvMap .writeJoinVal(this , field, value)
431
431
}
432
432
@@ -527,20 +527,20 @@ class Objects(using Context @constructorOnly):
527
527
_of(Map .empty, byNameParam, thisV, outerEnv)
528
528
529
529
def setLocalVal (x : Symbol , value : Value )(using scope : Scope , ctx : Context , heap : Heap .MutableData , envMap : EnvMap .EnvMapMutableData ): Unit =
530
- assert(! x.isOneOf (Flags .Param | Flags .Mutable ), " Only local immutable variable allowed" )
530
+ assert(x.is (Flags .Param ) || ! x.is( Flags .Mutable ), " Only local immutable variable allowed" )
531
531
scope match
532
532
case env : EnvRef =>
533
533
env.initVal(x, value)
534
534
case ref : Ref =>
535
- ref.initVal(x, value) // TODO: This is possible for match statement in class body. Report warning?
535
+ ref.initVal(x, value) // This is possible for match statement in class body.
536
536
537
537
def setLocalVar (x : Symbol , value : Value )(using scope : Scope , ctx : Context , heap : Heap .MutableData , envMap : EnvMap .EnvMapMutableData ): Unit =
538
538
assert(x.is(Flags .Mutable , butNot = Flags .Param ), " Only local mutable variable allowed" )
539
539
scope match
540
540
case env : EnvRef =>
541
541
env.initVar(x, value)
542
542
case ref : Ref =>
543
- ref.initVar(x, value) // TODO: This is possible for match statement in class body. Report warning?
543
+ ref.initVar(x, value) // This is possible for match statement in class body.
544
544
545
545
/**
546
546
* Resolve the environment by searching for a given symbol.
@@ -986,15 +986,7 @@ class Objects(using Context @constructorOnly):
986
986
// Assume such method is pure. Check return type, only try to analyze body if return type is not safe
987
987
val target = resolve(v.typeSymbol.asClass, meth)
988
988
val targetType = target.denot.info
989
- assert(targetType.isInstanceOf [ExprType ] || targetType.isInstanceOf [MethodType ],
990
- " Unexpected type! Receiver = " + v.show + " , meth = " + target + " , type = " + targetType)
991
- val returnType =
992
- if targetType.isInstanceOf [ExprType ] then
993
- // corresponds to parameterless method like `def meth: ExprType[T]`
994
- // See pos/toDouble.scala
995
- targetType.asInstanceOf [ExprType ].resType
996
- else
997
- targetType.asInstanceOf [MethodType ].resType
989
+ val returnType = targetType.finalResultType
998
990
val typeSymbol = SafeValue .getSafeTypeSymbol(returnType)
999
991
if typeSymbol.isDefined then
1000
992
// since method is pure and return type is safe, no need to analyze method body
@@ -1326,7 +1318,8 @@ class Objects(using Context @constructorOnly):
1326
1318
report.warning(" [Internal error] top-level class should have `Package` as outer, class = " + klass.show + " , outer = " + outer.show + " , " + Trace .show, Trace .position)
1327
1319
(Bottom , Env .NoEnv )
1328
1320
else
1329
- val outerCls = klass.owner.enclosingClass.asClass
1321
+ // enclosingClass is specially handled for java static terms, so use `lexicallyEnclosingClass` here
1322
+ val outerCls = klass.owner.lexicallyEnclosingClass.asClass
1330
1323
// When `klass` is directly nested in `outerCls`, `outerCls`.enclosingMethod returns its primary constructor
1331
1324
if klass.owner.enclosingMethod == outerCls.primaryConstructor then
1332
1325
(outer, Env .NoEnv )
0 commit comments