@@ -33,20 +33,24 @@ object Nullables:
33
33
&& hi.isValueType
34
34
// We cannot check if hi is nullable, because it can cause cyclic reference.
35
35
36
- /** Create a nullable type bound
36
+ private def nullifiedHi (lo : Type , hi : Type )(using Context ): Type =
37
+ if needNullifyHi(lo, hi) then
38
+ if ctx.flexibleTypes then FlexibleType (hi) else OrType (hi, defn.NullType , soft = false )
39
+ else hi
40
+
41
+ /** Create a nullable type bound
37
42
* If lo is `Null`, `| Null` is added to hi
38
43
*/
39
44
def createNullableTypeBounds (lo : Type , hi : Type )(using Context ): TypeBounds =
40
- val newHi = if needNullifyHi(lo, hi) then OrType (hi, defn.NullType , soft = false ) else hi
41
- TypeBounds (lo, newHi)
45
+ TypeBounds (lo, nullifiedHi(lo, hi))
42
46
43
47
/** Create a nullable type bound tree
44
48
* If lo is `Null`, `| Null` is added to hi
45
49
*/
46
50
def createNullableTypeBoundsTree (lo : Tree , hi : Tree , alias : Tree = EmptyTree )(using Context ): TypeBoundsTree =
47
- val hiTpe = hi.typeOpt
48
- val newHi = if needNullifyHi(lo .typeOpt, hiTpe) then TypeTree (OrType ( hiTpe, defn. NullType , soft = false )) else hi
49
- TypeBoundsTree (lo, newHi , alias)
51
+ val hiTpe = nullifiedHi(lo.typeOpt, hi.typeOpt)
52
+ val hiTree = if (hiTpe eq hi .typeOpt) hi else TypeTree (hiTpe)
53
+ TypeBoundsTree (lo, hiTree , alias)
50
54
51
55
/** A set of val or var references that are known to be not null, plus a set of
52
56
* variable references that are not known (anymore) to be not null
0 commit comments