Skip to content

Commit 2f4a3d4

Browse files
committed
Re-infer inferred types of ValDefs and DefDefs
# Conflicts: # compiler/src/dotty/tools/dotc/Compiler.scala # compiler/src/dotty/tools/dotc/typer/RefineTypes.scala
1 parent 1ee3c51 commit 2f4a3d4

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,6 +501,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
501501
"<derived typetree watching " ~ tpt.watched.showSummary() ~ ">"
502502
case TypeTree() =>
503503
typeText(toText(tree.typeOpt))
504+
~ Str("(inf)").provided(tree.isInstanceOf[InferredTypeTree[_]] && printDebug)
504505
case SingletonTypeTree(ref) =>
505506
toTextLocal(ref) ~ "." ~ keywordStr("type")
506507
case RefinedTypeTree(tpt, refines) =>

compiler/src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1802,8 +1802,15 @@ class Typer extends Namer
18021802
bindings1, expansion1)
18031803
}
18041804

1805+
def completeTypeTree(tree: untpd.TypeTree, pt: Type, original: untpd.Tree)(using Context): TypeTree =
1806+
tree.withSpan(original.span).withAttachmentsFrom(original)
1807+
.withType(
1808+
if isFullyDefined(pt, ForceDegree.flipBottom) then pt
1809+
else if ctx.reporter.errorsReported then UnspecifiedErrorType
1810+
else errorType(i"cannot infer type; expected type $pt is not fully defined", tree.srcPos))
1811+
18051812
def typedTypeTree(tree: untpd.TypeTree, pt: Type)(using Context): Tree =
1806-
tree match {
1813+
tree match
18071814
case tree: untpd.DerivedTypeTree =>
18081815
tree.ensureCompletions
18091816
tree.getAttachment(untpd.OriginalSymbol) match {
@@ -1817,11 +1824,7 @@ class Typer extends Namer
18171824
errorTree(tree, "Something's wrong: missing original symbol for type tree")
18181825
}
18191826
case _ =>
1820-
tree.withType(
1821-
if (isFullyDefined(pt, ForceDegree.flipBottom)) pt
1822-
else if (ctx.reporter.errorsReported) UnspecifiedErrorType
1823-
else errorType(i"cannot infer type; expected type $pt is not fully defined", tree.srcPos))
1824-
}
1827+
completeTypeTree(InferredTypeTree(), pt, tree)
18251828

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

0 commit comments

Comments
 (0)