Skip to content

Various refactorings #12938

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 12 commits into from
Jul 5, 2021
Merged
Prev Previous commit
Next Next commit
Re-infer inferred types of ValDefs and DefDefs
# Conflicts:
#	compiler/src/dotty/tools/dotc/Compiler.scala
#	compiler/src/dotty/tools/dotc/typer/RefineTypes.scala
  • Loading branch information
odersky committed Jun 25, 2021
commit 2f4a3d4f0f2ff82cff6193a2435fe506957c1664
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
"<derived typetree watching " ~ tpt.watched.showSummary() ~ ">"
case TypeTree() =>
typeText(toText(tree.typeOpt))
~ Str("(inf)").provided(tree.isInstanceOf[InferredTypeTree[_]] && printDebug)
case SingletonTypeTree(ref) =>
toTextLocal(ref) ~ "." ~ keywordStr("type")
case RefinedTypeTree(tpt, refines) =>
Expand Down
17 changes: 10 additions & 7 deletions compiler/src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1802,8 +1802,15 @@ class Typer extends Namer
bindings1, expansion1)
}

def completeTypeTree(tree: untpd.TypeTree, pt: Type, original: untpd.Tree)(using Context): TypeTree =
tree.withSpan(original.span).withAttachmentsFrom(original)
.withType(
if isFullyDefined(pt, ForceDegree.flipBottom) then pt
else if ctx.reporter.errorsReported then UnspecifiedErrorType
else errorType(i"cannot infer type; expected type $pt is not fully defined", tree.srcPos))

def typedTypeTree(tree: untpd.TypeTree, pt: Type)(using Context): Tree =
tree match {
tree match
case tree: untpd.DerivedTypeTree =>
tree.ensureCompletions
tree.getAttachment(untpd.OriginalSymbol) match {
Expand All @@ -1817,11 +1824,7 @@ class Typer extends Namer
errorTree(tree, "Something's wrong: missing original symbol for type tree")
}
case _ =>
tree.withType(
if (isFullyDefined(pt, ForceDegree.flipBottom)) pt
else if (ctx.reporter.errorsReported) UnspecifiedErrorType
else errorType(i"cannot infer type; expected type $pt is not fully defined", tree.srcPos))
}
completeTypeTree(InferredTypeTree(), pt, tree)

def typedSingletonTypeTree(tree: untpd.SingletonTypeTree)(using Context): SingletonTypeTree = {
val ref1 = typedExpr(tree.ref)
Expand Down Expand Up @@ -2736,7 +2739,7 @@ class Typer extends Namer
case tree: untpd.TypedSplice => typedTypedSplice(tree)
case tree: untpd.UnApply => typedUnApply(tree, pt)
case tree: untpd.Tuple => typedTuple(tree, pt)
case tree: untpd.DependentTypeTree => typed(untpd.TypeTree().withSpan(tree.span), pt)
case tree: untpd.DependentTypeTree => completeTypeTree(untpd.TypeTree(), pt, tree)
case tree: untpd.InfixOp => typedInfixOp(tree, pt)
case tree: untpd.ParsedTry => typedTry(tree, pt)
case tree @ untpd.PostfixOp(qual, Ident(nme.WILDCARD)) => typedAsFunction(tree, pt)
Expand Down