File tree 3 files changed +23
-8
lines changed
compiler/src/dotty/tools/dotc/core
3 files changed +23
-8
lines changed Original file line number Diff line number Diff line change @@ -2098,25 +2098,27 @@ object SymDenotations {
2098
2098
computeTypeProxy
2099
2099
2100
2100
case tp : AndOrType =>
2101
- def computeAndOrType = {
2101
+ def computeAndOrType : Type =
2102
2102
val tp1 = tp.tp1
2103
2103
val tp2 = tp.tp2
2104
+ if ! tp.isAnd then
2105
+ if tp1.isBottomType && (tp1 frozen_<:< tp2) then return recur(tp2)
2106
+ if tp2.isBottomType && (tp2 frozen_<:< tp1) then return recur(tp1)
2104
2107
val baseTp =
2105
- if ( symbol.isStatic && tp.derivesFrom(symbol) && symbol.typeParams.isEmpty)
2108
+ if symbol.isStatic && tp.derivesFrom(symbol) && symbol.typeParams.isEmpty then
2106
2109
symbol.typeRef
2107
- else {
2110
+ else
2108
2111
val baseTp1 = recur(tp1)
2109
2112
val baseTp2 = recur(tp2)
2110
2113
val combined = if (tp.isAnd) baseTp1 & baseTp2 else baseTp1 | baseTp2
2111
- combined match {
2114
+ combined match
2112
2115
case combined : AndOrType
2113
2116
if (combined.tp1 eq tp1) && (combined.tp2 eq tp2) && (combined.isAnd == tp.isAnd) => tp
2114
2117
case _ => combined
2115
- }
2116
- }
2118
+
2117
2119
if (baseTp.exists && inCache(tp1) && inCache(tp2)) record(tp, baseTp)
2118
2120
baseTp
2119
- }
2121
+
2120
2122
computeAndOrType
2121
2123
2122
2124
case JavaArrayType (_) if symbol == defn.ObjectClass =>
Original file line number Diff line number Diff line change @@ -3148,7 +3148,10 @@ object Types {
3148
3148
/** Replace or type by the closest non-or type above it */
3149
3149
def join (using Context ): Type = {
3150
3150
if (myJoinPeriod != ctx.period) {
3151
- myJoin = TypeOps .orDominator(this )
3151
+ myJoin =
3152
+ if tp1 frozen_<:< tp2 then tp2
3153
+ else if tp2 frozen_<:< tp1 then tp1
3154
+ else TypeOps .orDominator(this )
3152
3155
core.println(i " join of $this == $myJoin" )
3153
3156
assert(myJoin != this )
3154
3157
myJoinPeriod = ctx.period
Original file line number Diff line number Diff line change
1
+ class C {
2
+ def get (): Int = 0
3
+ }
4
+
5
+ def g = {
6
+ val s : String | Null = ???
7
+ val l = s.length // ok
8
+ val c : C | Null = ???
9
+ c.get() // error: value get is not a member of C | Null
10
+ }
You can’t perform that action at this time.
0 commit comments