diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index fd8507a7d961..ed37a869d612 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -205,7 +205,7 @@ object Inferencing { private def instantiate(tvar: TypeVar, fromBelow: Boolean): Boolean = if fromBelow && force.canImprove(tvar) then val inst = tvar.typeToInstantiateWith(fromBelow = true) - if apply(true, inst) then + if isFullyDefined(inst, ForceDegree.none) then // need to recursively check before improving, since improving adds type vars // which should not be instantiated at this point val better = improve(tvar)(inst) diff --git a/tests/pos/i19637.scala b/tests/pos/i19637.scala new file mode 100644 index 000000000000..53e609407bd0 --- /dev/null +++ b/tests/pos/i19637.scala @@ -0,0 +1,11 @@ +import java.util.stream.* +import java.util.function.* + +val map: java.util.Map[String, String] = Stream.of("1", "2", "3").collect(Collectors.toMap( + (s: String) => s, + Function.identity(), + { + case ("1", "1") => "1" + case (_, l) => l + } +))