Skip to content

Commit d6b9fce

Browse files
committed
Ignore implicit parameters when interpolating type variables.
Fixes scala#738. The previous scheme interpolated type variables according to the full variance of the result type. This means that the interpolation direction is downwards if a type varaible occurs like this: (implicit x: T)T but it is upwards if it occurs like this (implicit x: T)Unit For a normal method this makes sense, since the upper bound of T gives you the most general function. But if the method is implicit, it makes no sense, since upward instantiation means that we likely get ambiguity errors. Interestingly the fix causes a different problem (exemplified by failures in run/stream-stack-overflow.scala, and also in dotc itself), which will be fixed in the next commit.
1 parent 3d09c68 commit d6b9fce

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,14 @@ trait Inferencing { this: Checking =>
290290
if (v == null) vmap.updated(t, variance)
291291
else if (v == variance) vmap
292292
else vmap.updated(t, 0)
293+
case t: ImplicitMethodType =>
294+
// Assume type vars in implicit parameters are non-variant, in order not
295+
// to widen them prematurely to upper bound if they don't occur in the result type.
296+
val saved = variance
297+
variance = 0
298+
val vmap1 = foldOver(vmap, t.paramTypes)
299+
variance = saved
300+
this(vmap1, t.resultType)
293301
case _ =>
294302
foldOver(vmap, t)
295303
}

0 commit comments

Comments
 (0)