Skip to content

Simplify lubs in TreeUnpickler #15105

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

Merged
merged 2 commits into from
May 5, 2022
Merged
Show file tree
Hide file tree
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
29 changes: 18 additions & 11 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ class TreeUnpickler(reader: TastyReader,
class Completer(reader: TastyReader)(using @constructorOnly _ctx: Context) extends LazyType {
import reader._
val owner = ctx.owner
val mode = ctx.mode
val source = ctx.source
def complete(denot: SymDenotation)(using Context): Unit =
def fail(ex: Throwable) =
Expand All @@ -129,7 +130,7 @@ class TreeUnpickler(reader: TastyReader,
try
atPhaseBeforeTransforms {
new TreeReader(reader).readIndexedDef()(
using ctx.withOwner(owner).withSource(source))
using ctx.withOwner(owner).withModeBits(mode).withSource(source))
}
catch
case ex: AssertionError => fail(ex)
Expand Down Expand Up @@ -1193,6 +1194,10 @@ class TreeUnpickler(reader: TastyReader,
res.withAttachment(SuppressedApplyToNone, ())
else res

def simplifyLub(tree: Tree): Tree =
tree.overwriteType(tree.tpe.simplified)
tree

def readLengthTerm(): Tree = {
val end = readEnd()
val result =
Expand Down Expand Up @@ -1242,23 +1247,25 @@ class TreeUnpickler(reader: TastyReader,
val tpt = ifBefore(end)(readTpt(), EmptyTree)
Closure(Nil, meth, tpt)
case MATCH =>
if (nextByte == IMPLICIT) {
readByte()
InlineMatch(EmptyTree, readCases(end))
}
else if (nextByte == INLINE) {
readByte()
InlineMatch(readTerm(), readCases(end))
}
else Match(readTerm(), readCases(end))
simplifyLub(
if (nextByte == IMPLICIT) {
readByte()
InlineMatch(EmptyTree, readCases(end))
}
else if (nextByte == INLINE) {
readByte()
InlineMatch(readTerm(), readCases(end))
}
else Match(readTerm(), readCases(end)))
case RETURN =>
val from = readSymRef()
val expr = ifBefore(end)(readTerm(), EmptyTree)
Return(expr, Ident(from.termRef))
case WHILE =>
WhileDo(readTerm(), readTerm())
case TRY =>
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree))
simplifyLub(
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree)))
case SELECTouter =>
val levels = readNat()
readTerm().outerSelect(levels, SkolemType(readType()))
Expand Down
30 changes: 30 additions & 0 deletions tests/pos/i15097.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
class C:
def g: String | Null = ???

def f =
import scala.language.unsafeNulls
try g catch case _ => ""

def f2 =
import scala.language.unsafeNulls
if ??? then g else ""

def f3 =
(??? : Boolean) match
case true => g
case _ => ""

class C2:
import scala.language.unsafeNulls
def g: String | Null = ???

def f =
try g catch case _ => ""

def f2 =
if ??? then g else ""

def f3 =
(??? : Boolean) match
case true => g
case _ => ""