Backport #15679: Don't ignore expected types of New#15754
Merged
Conversation
A problem arises if we typecheck an expression like `new C()` with expected type `C[U]` where `C` is defined like this ```scala class C[X](using X)() ``` In this case, we'd like to propagate `U` as the type instance of `X` before we resolve the using clause. To do this, we have to keep the expected result type `C[X]` for typechecking the function part `new C`. Previously, that type was wrapped in an IgnoredProto. The problem was detected now since a class C with just the using clause and no empty parameter clause was previously expanded to ```scala class C[X]()(using X) ``` but is now expanded to ```scala class C[X](using X)() ``` Under the previous expansion, we type checked and `new C()` before looking for an argument of the using clause, so the problem did not arise.
It turns out an sjsJUnitTest fails otherwise, since that one _does_ insert an implicit conversion after a `new`. This is all goes to show that what we do to deal with implicit conversions is completely crazy. It's a black art when to propagate exected types. There's often no better or worse. Almost any change we do can heal some code and break some other code. I believe the only way to get our of this swamp is to get rid of unrestricted implicit conversions.
23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #15679