Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intercept TypeApply in explicit nulls #14617

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/transform/Erasure.scala
Original file line number Diff line number Diff line change
@@ -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) =>
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