Skip to content

Commit 067ec20

Browse files
authored
More careful type variable instance improvements (#19659)
The previous code tried to recursively apply the current instance of FullyDefinedAccumulator to the prospective instance type. This can have unforeseen side-effects, as i19637 shows. We now are more conservative: We check that the prospective instance type is already fully defined without the possibility to instantiate more type variables. This still passes the test cases that type variable improvement solves and avoids the problem with #19637. Fixes #19637
2 parents 5a5ea06 + 4700e3f commit 067ec20

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ object Inferencing {
205205
private def instantiate(tvar: TypeVar, fromBelow: Boolean): Boolean =
206206
if fromBelow && force.canImprove(tvar) then
207207
val inst = tvar.typeToInstantiateWith(fromBelow = true)
208-
if apply(true, inst) then
208+
if isFullyDefined(inst, ForceDegree.none) then
209209
// need to recursively check before improving, since improving adds type vars
210210
// which should not be instantiated at this point
211211
val better = improve(tvar)(inst)

tests/pos/i19637.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import java.util.stream.*
2+
import java.util.function.*
3+
4+
val map: java.util.Map[String, String] = Stream.of("1", "2", "3").collect(Collectors.toMap(
5+
(s: String) => s,
6+
Function.identity(),
7+
{
8+
case ("1", "1") => "1"
9+
case (_, l) => l
10+
}
11+
))

0 commit comments

Comments
 (0)