Skip to content

Commit 55ad7eb

Browse files
committed
Make inherited inferred result type work for dependent methods
We did not properly rename parameter references before.
1 parent bdb425c commit 55ad7eb

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

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

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ class Namer { typer: Typer =>
726726
// the parent types are elaborated.
727727
index(constr)
728728
symbolOfTree(constr).ensureCompleted()
729-
729+
730730
index(rest)(inClassContext(selfInfo))
731731

732732
val tparamAccessors = decls.filter(_ is TypeParamAccessor).toList
@@ -807,20 +807,27 @@ class Namer { typer: Typer =>
807807
lazy val schema = paramFn(WildcardType)
808808
val site = sym.owner.thisType
809809
((NoType: Type) /: sym.owner.info.baseClasses.tail) { (tp, cls) =>
810-
val iRawInfo =
811-
cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema).info
812-
val iInstInfo = iRawInfo match {
813-
case iRawInfo: PolyType =>
814-
if (iRawInfo.paramNames.length == typeParams.length)
815-
iRawInfo.instantiate(typeParams map (_.typeRef))
810+
def instantiatedResType(info: Type, tparams: List[Symbol], paramss: List[List[Symbol]]): Type = info match {
811+
case info: PolyType =>
812+
if (info.paramNames.length == typeParams.length)
813+
instantiatedResType(info.instantiate(tparams.map(_.typeRef)), Nil, paramss)
816814
else NoType
815+
case info: MethodType =>
816+
paramss match {
817+
case params :: paramss1 if info.paramNames.length == params.length =>
818+
instantiatedResType(info.instantiate(params.map(_.termRef)), tparams, paramss1)
819+
case _ =>
820+
NoType
821+
}
817822
case _ =>
818-
if (typeParams.isEmpty) iRawInfo
823+
if (tparams.isEmpty && paramss.isEmpty) info.widenExpr
819824
else NoType
820825
}
821-
val iResType = iInstInfo.finalResultType.asSeenFrom(site, cls)
826+
val iRawInfo =
827+
cls.info.nonPrivateDecl(sym.name).matchingDenotation(site, schema).info
828+
val iResType = instantiatedResType(iRawInfo, typeParams, paramss).asSeenFrom(site, cls)
822829
if (iResType.exists)
823-
typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inst: $iInstInfo, inherited: $iResType")
830+
typr.println(i"using inherited type for ${mdef.name}; raw: $iRawInfo, inherited: $iResType")
824831
tp & iResType
825832
}
826833
}

tests/pending/pos/t7668.scala renamed to tests/pos/t7668.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ trait Extractor {
88
}
99

1010
class Sub extends Extractor {
11-
def extract(s: Space) = s.x
11+
def extract(ss: Space) = ss.x
1212
}

0 commit comments

Comments
 (0)