@@ -57,7 +57,7 @@ class Semantic {
57
57
58
58
/** The current object under initialization
59
59
*/
60
- case class Objekt (val fields : mutable.Map [Symbol , Value ]) {
60
+ case class Objekt (klass : ClassSymbol , val fields : mutable.Map [Symbol , Value ]) {
61
61
var allFieldsInitialized : Boolean = false
62
62
63
63
val promotedValues = mutable.Set .empty[Value ]
@@ -501,7 +501,7 @@ class Semantic {
501
501
ref match
502
502
case Select (supert : Super , _) =>
503
503
val SuperType (thisTp, superTp) = supert.tpe
504
- val thisValue2 = resolveThis(thisTp.classSymbol.asClass, thisV, klass)
504
+ val thisValue2 = resolveThis(thisTp.classSymbol.asClass, thisV, klass, ref )
505
505
Result (thisValue2, errors).call(ref.symbol, superTp, expr)(using heap, ctx, trace2)
506
506
507
507
case Select (qual, _) =>
@@ -513,7 +513,7 @@ class Semantic {
513
513
case TermRef (NoPrefix , _) =>
514
514
// resolve this for the local method
515
515
val enclosingClass = id.symbol.owner.enclosingClass.asClass
516
- val thisValue2 = resolveThis(enclosingClass, thisV, klass)
516
+ val thisValue2 = resolveThis(enclosingClass, thisV, klass, id )
517
517
thisValue2 match
518
518
case Hot => Result (Hot , errors)
519
519
case _ =>
@@ -652,7 +652,7 @@ class Semantic {
652
652
case tp @ ThisType (tref) =>
653
653
if tref.symbol.is(Flags .Package ) then Result (Hot , noErrors)
654
654
else
655
- val value = resolveThis(tref.classSymbol.asClass, thisV, klass)
655
+ val value = resolveThis(tref.classSymbol.asClass, thisV, klass, source )
656
656
Result (value, noErrors)
657
657
658
658
case _ : TermParamRef | _ : RecThis =>
@@ -665,8 +665,9 @@ class Semantic {
665
665
}
666
666
667
667
/** Resolve C.this that appear in `klass` */
668
- def resolveThis (target : ClassSymbol , thisV : Value , klass : ClassSymbol ): Contextual [Value ] = log(" resolving " + target.show + " , this = " + thisV.show + " in " + klass.show, printer, res => res.asInstanceOf [Value ].show) {
668
+ def resolveThis (target : ClassSymbol , thisV : Value , klass : ClassSymbol , source : Tree ): Contextual [Value ] = log(" resolving " + target.show + " , this = " + thisV.show + " in " + klass.show, printer, res => res.asInstanceOf [Value ].show) {
669
669
if target == klass then thisV
670
+ else if target.is(Flags .Package ) || target.isStaticOwner && target != heap.klass then Hot
670
671
else
671
672
thisV match
672
673
case Hot | _ : ThisRef => Hot
@@ -676,22 +677,24 @@ class Semantic {
676
677
if tref.prefix == NoPrefix then
677
678
// Current class is local, in the enclosing scope of `warm.klass`
678
679
val outerCls = warm.klass.owner.enclosingClass.asClass
679
- resolveThis(target, warm.outer, outerCls)
680
+ resolveThis(target, warm.outer, outerCls, source )
680
681
else
681
682
val outerCls = klass.owner.enclosingClass.asClass
682
683
val warmOuterCls = warm.klass.owner.enclosingClass.asClass
683
- val res = cases(tref.prefix, warm.outer, warmOuterCls, EmptyTree )
684
+ val res = cases(tref.prefix, warm.outer, warmOuterCls, source )
684
685
assert(res.errors.isEmpty, " unexpected error " + res)
685
- resolveThis(target, res.value, outerCls)
686
- case _ => ???
686
+ resolveThis(target, res.value, outerCls, source)
687
+ case _ =>
688
+ // report.error("unexpected thisV = " + thisV + ", target = " + target.show + ", klass = " + klass.show, source.srcPos)
689
+ Cold
687
690
}
688
691
689
692
/** Compute the outer value that correspond to `tref.prefix` */
690
693
def outerValue (tref : TypeRef , thisV : Value , klass : ClassSymbol , source : Tree ): Contextual [Result ] =
691
694
val cls = tref.classSymbol.asClass
692
695
if tref.prefix == NoPrefix then
693
696
val enclosing = cls.owner.lexicallyEnclosingClass.asClass
694
- val outerV = resolveThis(enclosing, thisV, klass)
697
+ val outerV = resolveThis(enclosing, thisV, klass, source )
695
698
Result (outerV, noErrors)
696
699
else
697
700
cases(tref.prefix, thisV, klass, source)
0 commit comments