Skip to content

Commit 8f70097

Browse files
authored
Fix captureWildcards with FlexibleType (#24070)
Apply `captureWildcards` inside `FlexibleType` as well ```scala import java.util.stream._ val seqStream: Stream[String] = ??? val shouldNotNPE = seqStream.collect(Collectors.toList()) ```
2 parents 611f240 + d0ec082 commit 8f70097

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,11 +626,13 @@ object Inferencing {
626626
case tp: RecType => tp.derivedRecType(captureWildcards(tp.parent))
627627
case tp: LazyRef => captureWildcards(tp.ref)
628628
case tp: AnnotatedType => tp.derivedAnnotatedType(captureWildcards(tp.parent), tp.annot)
629+
case tp: FlexibleType => tp.derivedFlexibleType(captureWildcards(tp.hi))
629630
case _ => tp
630631
}
631632

632633
def hasCaptureConversionArg(tp: Type)(using Context): Boolean = tp match
633634
case tp: AppliedType => tp.args.exists(_.typeSymbol == defn.TypeBox_CAP)
635+
case tp: FlexibleType => hasCaptureConversionArg(tp.hi)
634636
case _ => false
635637
}
636638

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java.util.stream._
2+
3+
def test =
4+
val seqStream: Stream[String] = ???
5+
val shouldNotNPE = seqStream.collect(Collectors.toList())
6+
val shouldNotNPE2 = seqStream.collect(Collectors.toList[String]())

0 commit comments

Comments
 (0)