File tree 2 files changed +18
-5
lines changed
compiler/src/dotty/tools/dotc/transform/init 2 files changed +18
-5
lines changed Original file line number Diff line number Diff line change @@ -515,10 +515,18 @@ class Semantic {
515
515
promoted.isCurrentObjectPromoted || {
516
516
val obj = heap(thisRef)
517
517
// If we have all fields initialized, then we can promote This to hot.
518
- val allFieldsInitialized = thisRef.klass.appliedRef.fields.forall { denot =>
519
- val sym = denot.symbol
520
- sym.isOneOf(Flags .Lazy | Flags .Deferred ) || obj.fields.contains(sym)
518
+ val allFieldsInitialized = thisRef.klass.baseClasses.forall { klass =>
519
+ if klass.hasSource then
520
+ val nonInits = klass.info.decls.filter { member =>
521
+ ! member.isOneOf(Flags .Method | Flags .Lazy | Flags .Deferred )
522
+ && ! member.isType
523
+ && ! obj.fields.contains(member)
524
+ }
525
+ nonInits.isEmpty
526
+ else
527
+ true
521
528
}
529
+
522
530
if allFieldsInitialized then promoted.promoteCurrent(thisRef)
523
531
allFieldsInitialized
524
532
}
@@ -535,8 +543,7 @@ class Semantic {
535
543
case Cold => PromoteError (msg, source, trace.toVector) :: Nil
536
544
537
545
case thisRef : ThisRef =>
538
- if promoted.contains(thisRef) then Nil
539
- else if thisRef.tryPromoteCurrentObject then Nil
546
+ if thisRef.tryPromoteCurrentObject then Nil
540
547
else PromoteError (msg, source, trace.toVector) :: Nil
541
548
542
549
case warm : Warm =>
Original file line number Diff line number Diff line change
1
+ class M {
2
+ println(this ) // error
3
+ foo()
4
+ private val a = 5 // error
5
+ def foo () = a
6
+ }
You can’t perform that action at this time.
0 commit comments