Skip to content

Commit 4133b83

Browse files
committed
Move tracked inference logic to inferredResultType
1 parent 28b5725 commit 4133b83

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ object Flags {
480480
*/
481481
val AfterLoadFlags: FlagSet = commonFlags(
482482
FromStartFlags, AccessFlags, Final, AccessorOrSealed,
483-
Abstract, LazyOrTrait, SelfName, JavaDefined, JavaAnnotation, Transparent, Tracked)
483+
Abstract, LazyOrTrait, SelfName, JavaDefined, JavaAnnotation, Transparent)
484484

485485
/** A value that's unstable unless complemented with a Stable flag */
486486
val UnstableValueFlags: FlagSet = Mutable | Method

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -907,16 +907,6 @@ class Namer { typer: Typer =>
907907
case _ =>
908908
}
909909

910-
private def setAbstractTrackedInfo(sym: Symbol)(using Context): Unit =
911-
if !sym.flags.is(ParamAccessor) && !sym.flags.is(Param) then
912-
if sym.allOverriddenSymbols.exists(_.flags.is(Tracked)) then
913-
sym.setFlag(Tracked)
914-
if sym.flags.is(Tracked) then
915-
original match
916-
case tree: untpd.ValDef if tree.tpt.isEmpty =>
917-
sym.info = typedAheadExpr(tree.rhs).tpe
918-
case _ => ()
919-
920910
/** Invalidate `denot` by overwriting its info with `NoType` if
921911
* `denot` is a compiler generated case class method that clashes
922912
* with a user-defined method in the same scope with a matching type.
@@ -999,7 +989,6 @@ class Namer { typer: Typer =>
999989
addInlineInfo(sym)
1000990
denot.info = typeSig(sym)
1001991
invalidateIfClashingSynthetic(denot)
1002-
setAbstractTrackedInfo(sym)
1003992
Checking.checkWellFormed(sym)
1004993
denot.info = avoidPrivateLeaks(sym)
1005994
}
@@ -2062,12 +2051,17 @@ class Namer { typer: Typer =>
20622051
if paramss.isEmpty then info.widenExpr
20632052
else NoType
20642053

2065-
val iRawInfo =
2066-
cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema, sym.targetName).info
2054+
val iDenot = cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema, sym.targetName)
2055+
val iSym = iDenot.symbol
2056+
val iRawInfo = iDenot.info
20672057
val iResType = instantiatedResType(iRawInfo, paramss).asSeenFrom(site, cls)
2068-
if (iResType.exists)
2069-
typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inherited: $iResType")
2070-
tp & iResType
2058+
if iSym.is(Tracked) && !mdef.rhs.isEmpty then
2059+
// When inherting a tracked member, we infer a precise type from the rhs
2060+
tp & typedAheadExpr(mdef.rhs, iResType).tpe
2061+
else
2062+
if (iResType.exists)
2063+
typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inherited: $iResType")
2064+
tp & iResType
20712065
}
20722066
end inherited
20732067

0 commit comments

Comments
 (0)