Skip to content

Commit b2697e7

Browse files
committed
tpd#polyDefDef: Handle intra-parameter list dependencies
The paramInfos of a MethodType may contain TermParamRefs, when creating symbols for these parameters, the TermParamRefs need to be replaced by TermRef to previously created parameter symbols.
1 parent 5cbac9d commit b2697e7

File tree

2 files changed

+19
-2
lines changed

2 files changed

+19
-2
lines changed

compiler/src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,11 +200,24 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
200200

201201
def valueParamss(tp: Type): (List[List[TermSymbol]], Type) = tp match {
202202
case tp: MethodType =>
203-
def valueParam(name: TermName, info: Type): TermSymbol = {
203+
val isParamDependent = tp.isParamDependent
204+
val previousParamRefs = if (isParamDependent) new mutable.ListBuffer[TermRef]() else null
205+
206+
def valueParam(name: TermName, origInfo: Type): TermSymbol = {
204207
val maybeImplicit = if (tp.isImplicitMethod) Implicit else EmptyFlags
205208
val maybeErased = if (tp.isErasedMethod) Erased else EmptyFlags
206-
ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeErased, info, coord = sym.coord)
209+
210+
def makeSym(info: Type) = ctx.newSymbol(sym, name, TermParam | maybeImplicit | maybeErased, info, coord = sym.coord)
211+
212+
if (isParamDependent) {
213+
val sym = makeSym(origInfo.substParams(tp, previousParamRefs.toList))
214+
previousParamRefs += sym.termRef
215+
sym
216+
}
217+
else
218+
makeSym(origInfo)
207219
}
220+
208221
val params = (tp.paramNames, tp.paramInfos).zipped.map(valueParam)
209222
val (paramss, rtp) = valueParamss(tp.instantiate(params map (_.termRef)))
210223
(params :: paramss, rtp)

tests/pos/i4345.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,8 @@ class Test {
77
@tailrec
88
final def loop(c: Context)(trees: List[c.Tree]): Boolean =
99
loop(c)(trees)
10+
11+
@tailrec
12+
final def loop2(c: Context, trees: List[c.Tree]): Boolean =
13+
loop2(c, trees)
1014
}

0 commit comments

Comments
 (0)