From d0ec0824441ab68fd5415f0383530618644b9895 Mon Sep 17 00:00:00 2001 From: noti0na1 Date: Thu, 25 Sep 2025 11:34:58 +0200 Subject: [PATCH] Fix captureWildcards with FlexibleType --- compiler/src/dotty/tools/dotc/typer/Inferencing.scala | 2 ++ tests/explicit-nulls/pos/java-collectors.scala | 6 ++++++ 2 files changed, 8 insertions(+) create mode 100644 tests/explicit-nulls/pos/java-collectors.scala diff --git a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala index c581dac5ec52..b7861c236b73 100644 --- a/compiler/src/dotty/tools/dotc/typer/Inferencing.scala +++ b/compiler/src/dotty/tools/dotc/typer/Inferencing.scala @@ -626,11 +626,13 @@ object Inferencing { case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent)) case tp: LazyRef => captureWildcards(tp.ref) case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot) + case tp: FlexibleType => tp.derivedFlexibleType(captureWildcards(tp.hi)) case _ => tp } def hasCaptureConversionArg(tp: Type)(using Context): Boolean = tp match case tp: AppliedType => tp.args.exists(_.typeSymbol == defn.TypeBox_CAP) + case tp: FlexibleType => hasCaptureConversionArg(tp.hi) case _ => false } diff --git a/tests/explicit-nulls/pos/java-collectors.scala b/tests/explicit-nulls/pos/java-collectors.scala new file mode 100644 index 000000000000..ce9bc6b3033e --- /dev/null +++ b/tests/explicit-nulls/pos/java-collectors.scala @@ -0,0 +1,6 @@ +import java.util.stream._ + +def test = + val seqStream: Stream[String] = ??? + val shouldNotNPE = seqStream.collect(Collectors.toList()) + val shouldNotNPE2 = seqStream.collect(Collectors.toList[String]()) \ No newline at end of file