Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions compiler/src/dotty/tools/dotc/typer/Inferencing.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this one, I don't understand why the other cases are not needed (i.e. what makes FlexibleType special). For example, what if you get the right AppliedType under an AnnontatedType? In that case, this method won't find it either.

But the case for FlexibleType looks right to me.

Copy link
Member Author

@noti0na1 noti0na1 Sep 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The real fix is in captureWildcards. I guess hasCaptureConversionArg is only used to check top-level AppliedType of a tree for error messages. Maybe adding a stripped after tp can handle more cases, idk. Given the places where FlexibleType is expected to appear, I just added this case.

case _ => false
}

Expand Down
6 changes: 6 additions & 0 deletions tests/explicit-nulls/pos/java-collectors.scala
Original file line number Diff line number Diff line change
@@ -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]())
Loading