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

Try to be more subtle when inferring type parameters of class parents #16896

Merged
merged 2 commits into from
Feb 13, 2023

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Feb 12, 2023

The previous scheme was basically like this:

  1. If the parent type is an application, infer type parameters from the term parameters during completion of the class.
  2. If the parent type is an Ident or Select and it appears in an anonymous class, infer it from the expected type.

It could happen in the second case that we infer Nothing since an expected type was missing, but if the parent type had been an application, we would have inferred something else from implicit arguments to the parent constructor. This is a case handled by Scala 2, but not yet by Dotty.

To deal with this we have to perform a complicated dance:

  • Try step (2) above, but back out if the inferred parent type has Nothing as a type argument.
  • During completion, if the inferred parent has missing type arguments, convert the parent type to an application with () arguments and try that instead.

I normally would have thought this is too much sophistry but there are valid use cases that Scala 2 supports and it would be good if we get to parity for these.

Fixes #16778

The previous scheme was basically like this:

 1. If the parent type is an application, infer type parameters from the
   term parameters during completion of the class.
 2. If the parent type is an Ident or Select and it appears in an anonymous
   class, infer it from the expected type.

It could happen in the second case that we infer Nothing since an expected type
was missing, but if the parent type had been an application, we would have inferred
something else from implicit arguments to the parent constructor. This is a case
handled by Scala 2, but not yet by Dotty.

To deal with this we have to perform a complicated dance:

 - Try step (2) above, but back out if the inferred parent type has Nothing
   as a type argument.
 - During completion, if the inferred parent has missing type arguments, convert
   the parent type to an application with () arguments and try that instead.

I normally would have thought this is too much sophistry but there are valid
use cases that Scala 2 supports and it would be good if we get to parity for these.
@dwijnand dwijnand merged commit 1a4f3ac into scala:main Feb 13, 2023
@dwijnand dwijnand deleted the fix-16778 branch February 13, 2023 11:59
@Kordyjan Kordyjan added this to the 3.3.1 milestone 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.

Scala 2 regression: spurious missing implicit error when inheriting a class without call parentheses()
3 participants