Skip to content

Conversation

noti0na1
Copy link
Member

Apply captureWildcards inside FlexibleType as well

import java.util.stream._

val seqStream: Stream[String] = ???
val shouldNotNPE = seqStream.collect(Collectors.toList())

cc @HarrisL2

@noti0na1 noti0na1 requested a review from olhotak September 25, 2025 09:38
@noti0na1 noti0na1 assigned noti0na1 and olhotak and unassigned noti0na1 Sep 25, 2025
Copy link
Contributor

@olhotak olhotak left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM.


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.

@noti0na1 noti0na1 merged commit 8f70097 into scala:main Sep 26, 2025
50 checks passed
@noti0na1 noti0na1 deleted the fix-captureWildcards-flexible-type branch September 26, 2025 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants