Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restrict captureWildcards to only be used if needed #16799

Merged
merged 1 commit into from
Feb 4, 2023

Conversation

dwijnand
Copy link
Member

@dwijnand dwijnand commented Feb 1, 2023

Rather than blindly using the newly wildcard-captured type, check that
it's compatible with the proto/formal type. That way values that have
wildcard types can be passed, uncast, to extension methods that don't
require the capture.

For instance in specs2, a value of type Class[? <: Foo] needn't become
Class[?1.CAP] just so it can be applied to def theValue[T](t: => T).

For the zio-http case, despite knowing that JFuture is morally
covariant, we don't have any way to knowing that - so we must be safe
and error.

@dwijnand dwijnand added the backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. label Feb 1, 2023
@dwijnand dwijnand added this to the 3.3.0 backports milestone Feb 1, 2023
@SethTisue
Copy link
Member

seems really elegant!

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

Otherwise looks right to me.

compiler/src/dotty/tools/dotc/typer/Inferencing.scala Outdated Show resolved Hide resolved
@odersky odersky assigned dwijnand and unassigned odersky Feb 3, 2023
Rather than blindly using the newly wildcard-captured type, check that
it's compatible with the proto/formal type.  That way values that have
wildcard types can be passed, uncast, to extension methods that don't
require the capture.

For instance in specs2, a value of type `Class[? <: Foo]` needn't become
`Class[?1.CAP]` just so it can be applied to `def theValue[T](t: => T)`.

For the zio-http case, despite knowing that JFuture is morally
covariant, we don't have any way to knowing that - so we must be safe
and error.
@odersky odersky merged commit a356581 into scala:main Feb 4, 2023
@dwijnand dwijnand deleted the let-wildtypes-run-free branch February 4, 2023 11:07
@Kordyjan Kordyjan added backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" and removed backport:nominated If we agree to backport this PR, replace this tag with "backport:accepted", otherwise delete it. labels Feb 13, 2023
@dwijnand dwijnand removed the backport:accepted This PR needs to be backported, once it's been backported replace this tag by "backport:done" label Feb 16, 2023
@Kordyjan Kordyjan modified the milestones: 3.3.0 backports, 3.3.1 Aug 1, 2023
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.

Resolve how to handle errors of closures taking by-name arguments with wildcard types
4 participants