Skip to content

Commit

Permalink
Merge pull request #14617 from dotty-staging/fix-intercept-TypeApply-…
Browse files Browse the repository at this point in the history
…in-explicit-nulls

Fix intercept TypeApply in explicit nulls
  • Loading branch information
noti0na1 authored Mar 3, 2022
2 parents b20f5f7 + e563219 commit b0e7265
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -784,9 +784,11 @@ object Erasure {
}

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

ntree match {
case TypeApply(fun, args) =>
Expand Down
27 changes: 27 additions & 0 deletions tests/explicit-nulls/pos-patmat/match-pat.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Ensure we don't get "the type test for argType cannot be checked at runtime" warning

class Symbol {
type ThisName
}

type TermSymbol = Symbol { type ThisName = String }

type TermSymbolOrNull = TermSymbol | Null

def testSimple =
val x: Symbol | Null = ???
x match
case key: Symbol => 1
case null => 0

def testWithRefinedType =
val x: TermSymbol | Null = ???
x match
case key: TermSymbol => 1
case null => 0

def testWithAlias =
val x: TermSymbolOrNull = ???
x match
case key: TermSymbol => 1
case null => 0

0 comments on commit b0e7265

Please sign in to comment.