Skip to content

Commit 55524c5

Browse files
committed
Fix inference
1 parent 610b860 commit 55524c5

File tree

4 files changed

+22
-1
lines changed

4 files changed

+22
-1
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

+5-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import collection.{immutable, mutable}
1414
import util.{Property, SourceFile, NoSource}
1515
import NameKinds.{TempResultName, OuterSelectName}
1616
import typer.ConstFold
17+
import typer.Nullables
1718

1819
import scala.annotation.tailrec
1920
import scala.io.Codec
@@ -932,7 +933,10 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
932933

933934
/** The current tree applied to given type argument list: `tree[targs(0), ..., targs(targs.length - 1)]` */
934935
def appliedToTypeTrees(targs: List[Tree])(using Context): Tree =
935-
if (targs.isEmpty) tree else TypeApply(tree, targs)
936+
if (targs.isEmpty) tree else
937+
val app = TypeApply(tree, targs)
938+
app.putAttachment(Nullables.UnsafeNullsKey, config.Feature.enabled(nme.unsafeNulls))
939+
app
936940

937941
/** Apply to `()` unless tree's widened type is parameterless */
938942
def ensureApplied(using Context): Tree =

compiler/src/dotty/tools/dotc/core/NullOpsDecorator.scala

+2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ object NullOpsDecorator {
6565
case tp: TypeProxy => tp.underlying.isNullableAfterErasure
6666
case OrType(lhs, rhs) =>
6767
lhs.isNullableAfterErasure || rhs.isNullableAfterErasure
68+
case AndType(lhs, rhs) =>
69+
lhs.isNullableAfterErasure && rhs.isNullableAfterErasure
6870
case _ =>
6971
self.isNullType || self <:< defn.ObjectType
7072
}

compiler/src/dotty/tools/dotc/core/OrderingConstraint.scala

+2
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import config.Printers.constr
1212
import reflect.ClassTag
1313
import annotation.tailrec
1414
import annotation.internal.sharable
15+
import typer.Nullables
1516

1617
object OrderingConstraint {
1718

@@ -268,6 +269,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
268269
val nparams = poly.paramNames.length
269270
val entries1 = new Array[Type](nparams * 2)
270271
poly.paramInfos.copyToArray(entries1, 0)
272+
Nullables.nullifyUpperBounds(entries1)
271273
tvars.copyToArray(entries1, nparams)
272274
newConstraint(boundsMap.updated(poly, entries1), lowerMap, upperMap).init(poly)
273275
}

compiler/src/dotty/tools/dotc/typer/Nullables.scala

+13
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ object Nullables:
2626
config.Feature.enabled(nme.unsafeNulls) ||
2727
ctx.mode.is(Mode.UnsafeNullConversion))
2828

29+
def nullifyUpperBounds(tps: Array[Type])(using Context): Unit = {
30+
if convertUnsafeNulls then
31+
var i = 0
32+
while i < tps.length do
33+
tps(i) match {
34+
case bound: TypeBounds =>
35+
if bound.lo.isNullType && bound.hi.isNullableAfterErasure then
36+
tps(i) = bound.derivedTypeBounds(bound.lo, OrNull(bound.hi))
37+
case _ =>
38+
}
39+
i += 1
40+
}
41+
2942
val UnsafeNullsKey = Property.StickyKey[Boolean]
3043

3144
/** A set of val or var references that are known to be not null, plus a set of

0 commit comments

Comments
 (0)