Skip to content

Commit b0e7265

Browse files
authored
Merge pull request #14617 from dotty-staging/fix-intercept-TypeApply-in-explicit-nulls
Fix intercept TypeApply in explicit nulls
2 parents b20f5f7 + e563219 commit b0e7265

File tree

2 files changed

+32
-3
lines changed

2 files changed

+32
-3
lines changed

compiler/src/dotty/tools/dotc/transform/Erasure.scala

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -784,9 +784,11 @@ object Erasure {
784784
}
785785

786786
override def typedTypeApply(tree: untpd.TypeApply, pt: Type)(using Context): Tree = {
787-
val ntree = atPhase(erasurePhase)(
788-
interceptTypeApply(tree.asInstanceOf[TypeApply])
789-
).withSpan(tree.span)
787+
val ntree = atPhase(erasurePhase){
788+
// Use erased-type semantic to intercept TypeApply in explicit nulls
789+
val interceptCtx = if ctx.explicitNulls then ctx.retractMode(Mode.SafeNulls) else ctx
790+
interceptTypeApply(tree.asInstanceOf[TypeApply])(using interceptCtx)
791+
}.withSpan(tree.span)
790792

791793
ntree match {
792794
case TypeApply(fun, args) =>
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Ensure we don't get "the type test for argType cannot be checked at runtime" warning
2+
3+
class Symbol {
4+
type ThisName
5+
}
6+
7+
type TermSymbol = Symbol { type ThisName = String }
8+
9+
type TermSymbolOrNull = TermSymbol | Null
10+
11+
def testSimple =
12+
val x: Symbol | Null = ???
13+
x match
14+
case key: Symbol => 1
15+
case null => 0
16+
17+
def testWithRefinedType =
18+
val x: TermSymbol | Null = ???
19+
x match
20+
case key: TermSymbol => 1
21+
case null => 0
22+
23+
def testWithAlias =
24+
val x: TermSymbolOrNull = ???
25+
x match
26+
case key: TermSymbol => 1
27+
case null => 0

0 commit comments

Comments
 (0)