-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Don't ignore expected types of New
.
#15679
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
Conversation
It turns out an sjsJUnitTest fails without the second commit, since that one does insert an implicit conversion after a 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 expected types. There's often no better or worse. Almost any change we do can heal some code and break |
@odersky one project in the community build is failing but this seems unrelated to your changes. I think rebasing might fix the problem |
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.
Backport #15679: Don't ignore expected types of `New`
A problem arises if we typecheck an expression like
new C()
with expected typeC[U]
whereC
is defined like thisIn this case, we'd like to propagate
U
as the type instance ofX
before weresolve the using clause. To do this, we have to keep the expected result
type
C[X]
for typechecking the function partnew C
. Previously, that type was wrappedin 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
but is now expanded to
Under the previous expansion, we type checked and instantiated
new C()
before lookingfor an argument of the using clause, so the problem did not arise.
Fixes #15664