File tree 4 files changed +34
-3
lines changed
compiler/src/dotty/tools/dotc/core
4 files changed +34
-3
lines changed Original file line number Diff line number Diff line change @@ -116,14 +116,24 @@ class CheckRealizable(using Context) {
116
116
case _ : SingletonType | NoPrefix =>
117
117
Realizable
118
118
case tp =>
119
+ def checkAndType (x : TermRef , y : Type ) =
120
+ (realizability(x) eq Realizable ) && (y <:< x.widen)
121
+ val isStableAndType = tp match {
122
+ case AndType (tr : TermRef , tp1) =>
123
+ checkAndType(tr, tp1)
124
+ case AndType (tp1, tr : TermRef ) =>
125
+ checkAndType(tr, tp1)
126
+ case _ => false
127
+ }
119
128
def isConcrete (tp : Type ): Boolean = tp.dealias match {
120
129
case tp : TypeRef => tp.symbol.isClass
121
130
case tp : TypeProxy => isConcrete(tp.underlying)
122
131
case tp : AndType => isConcrete(tp.tp1) && isConcrete(tp.tp2)
123
132
case tp : OrType => isConcrete(tp.tp1) && isConcrete(tp.tp2)
124
133
case _ => false
125
134
}
126
- if (! isConcrete(tp)) NotConcrete
135
+ if isStableAndType then Realizable
136
+ else if ! isConcrete(tp) then NotConcrete
127
137
else boundsRealizability(tp).andAlso(memberRealizability(tp))
128
138
}
129
139
Original file line number Diff line number Diff line change @@ -170,8 +170,9 @@ object Types {
170
170
case tp : ExprType => tp.resultType.isStable
171
171
case tp : AnnotatedType => tp.parent.isStable
172
172
case tp : AndType =>
173
- tp.tp1.isStable && (realizability(tp.tp2) eq Realizable ) ||
174
- tp.tp2.isStable && (realizability(tp.tp1) eq Realizable )
173
+ def checkAndStable (x : Type , y : Type ) =
174
+ x.isStable && ((realizability(y) eq Realizable ) || y <:< x.widen)
175
+ checkAndStable(tp.tp1, tp.tp2) || checkAndStable(tp.tp2, tp.tp1)
175
176
case _ => false
176
177
}
177
178
Original file line number Diff line number Diff line change
1
+ // `.nn` extension method only strips away the outer Null.
2
+
3
+ class Test {
4
+ val s1 : String | Null = ???
5
+ val s2 : String = s1.nn
6
+
7
+ val ss1 : Array [String | Null ] | Null = ???
8
+ val ss2 : Array [String | Null ] = ss1.nn
9
+ val ss3 : Array [String ] = ss1.nn // error
10
+ }
Original file line number Diff line number Diff line change
1
+ class S {
2
+ def i [T ](x : T ): x.type = x
3
+
4
+ def f [T <: AnyRef ](x : T | Null ): x.type & T = {
5
+ if x != null then
6
+ i[x.type ](x)
7
+ else
8
+ throw Exception ()
9
+ }
10
+ }
You can’t perform that action at this time.
0 commit comments