Skip to content

Union types: deduplication + Nothing type members absorption #16312

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

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from
Draft
Prev Previous commit
commenting prints
  • Loading branch information
mucciolo committed Jun 16, 2023
commit 437150c1b0dd774dd60a6ce77259174927c9097c
34 changes: 17 additions & 17 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2425,9 +2425,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
val tpdType = typedType(tpt)
val tpt1: Tree = checkSimpleKinded(tpdType) match {
case inferred: InferredTypeTree =>
println(i"inferred type = $inferred")
// println(i"inferred type = $inferred")
inferred.tpe match {
case or @ OrType(l, r) =>
case or: OrType =>
inferred.overwriteType(or.deduplicatedAbsorbingNothingTypes)
case _ =>
}
Expand Down Expand Up @@ -3015,24 +3015,24 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
def typedUnadapted(initTree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree = {
record("typedUnadapted")
val xtree = expanded(initTree)
println("> typing unadapted")
println(i"initTree = $initTree")
println(i"pt = $pt")
// println("> typing unadapted")
// println(i"initTree = $initTree")
// println(i"pt = $pt")

xtree.removeAttachment(TypedAhead) match {
case Some(ttree) => ttree
case none =>

def typedNamed(tree: untpd.NameTree, pt: Type)(using Context): Tree = {
val sym = retrieveSym(xtree)
println(s"$tree")
// println(i"sym = $sym")
tree match {
case tree: untpd.Ident => typedIdent(tree, pt)
case tree: untpd.Select => typedSelect(tree, pt)
case tree: untpd.Bind => typedBind(tree, pt)
case tree: untpd.ValDef =>
println("> typing val def")
println(i"$tree")
// println("> typing val def")
// println(i"$tree")
if (tree.isEmpty) tpd.EmptyValDef
else typedValDef(tree, sym)(using ctx.localContext(tree, sym))
case tree: untpd.DefDef =>
Expand Down Expand Up @@ -3124,13 +3124,13 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
makeContextualFunction(xtree, ifpt)
else xtree match
case xtree: untpd.NameTree =>
println(s"> typing named")
println(i"xtree = $xtree")
println(i"pt = $pt")
// println(s"> typing named")
// println(i"xtree = $xtree")
// println(i"pt = $pt")
typedNamed(xtree, pt)
case xtree =>
println(s"> typing unnamed")
println(i"xtree = $xtree")
// println(s"> typing unnamed")
// println(i"xtree = $xtree")
typedUnnamed(xtree)

simplify(result, pt, locked)
Expand Down Expand Up @@ -3194,7 +3194,7 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer

/** Typecheck and adapt tree, returning a typed tree. Parameters as for `typedUnadapted` */
def typed(tree: untpd.Tree, pt: Type, locked: TypeVars)(using Context): Tree =
println("> typing tree")
// println("> typing tree")
trace(i"typing $tree, pt = $pt", typr, show = true) {
record(s"typed $getClass")
record("typed total")
Expand Down Expand Up @@ -3323,9 +3323,9 @@ class Typer(@constructorOnly nestingLevel: Int = 0) extends Namer
withoutMode(Mode.PatternOrTypeBits)(typed(tree, pt))

def typedType(tree: untpd.Tree, pt: Type = WildcardType, mapPatternBounds: Boolean = false)(using Context): Tree =
println("> typing type")
println(i"pt = $pt")
println(s"tree = $tree")
// println("> typing type")
// println(i"tree = $tree")
// println(i"pt = $pt")
val tree1 = withMode(Mode.Type) { typed(tree, pt) }
if mapPatternBounds && ctx.mode.is(Mode.Pattern) && !ctx.isAfterTyper then
tree1 match
Expand Down