Skip to content

Commit 998a11d

Browse files
EnzeXingolhotak
authored andcommitted
fix assigning to null
1 parent a187110 commit 998a11d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/transform/init/Objects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ class Objects(using Context @constructorOnly):
905905
// the typer might mistakenly set the receiver to be a package instead of package object.
906906
// See pos/packageObjectStringInterpolator.scala
907907
if packageModuleClass == klass || (klass.denot.isPackageObject && klass.owner == packageModuleClass) then a else Bottom
908-
case v: SafeValue => if v.typeSymbol.asClass.isSubClass(klass) then a else Bottom
908+
case v: SafeValue => if v.typeSymbol.asClass.isSubClass(klass) && v.typeSymbol.asClass != defn.NullClass then a else Bottom
909909
case ref: Ref => if ref.klass.isSubClass(klass) then ref else Bottom
910910
case ValueSet(values) => values.map(v => v.filterClass(klass)).join
911911
case fun: Fun =>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class C {
2+
var f: Int = 1
3+
}
4+
5+
object O {
6+
var c: C = null
7+
c = new C
8+
c.f = 2
9+
}

0 commit comments

Comments
 (0)