-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Harden Type Inference #12560
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
Harden Type Inference #12560
Conversation
Based on #12535. Best reviewed commit by commit. |
The purpose of canDefineFurther is to discover new members. That is not helped by instantiating a type variable to `Nothing`. Avoiding the instantiation helpos error messages. There was one test (i864.scala) that fails now but compiled previously with a surprising instantiation to Nothing. I believe it is better to issue an error message in this case.
We should retry adapt if we can instantiate typevars in either the type of the tree or the expected type
This was deemed too hard before for type inference, but it works now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise LGTM.
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5))) // ok, synthesizes (using ListMonad) | ||
MonadFlatten.flattened(List(List(1, 2, 3), List(4, 5)))(using ListMonad) // error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be clear: passing ListMonad explicitly already failed on master and this PR doesn't improve the situation but just documents it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, correct.
case SAMType(sam @ MethodTpe(_, formals, restpe)) => | ||
case RefinedType(parent, nme.apply, mt @ MethodTpe(_, formals, restpe)) | ||
if defn.isNonRefinedFunction(parent) && formals.length == defaultArity => | ||
(formals, untpd.DependentTypeTree(syms => restpe.substParams(mt, syms.map(_.termRef)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have a testcase for this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In fact I could not come up with one. The only test that fails in the SAM case was scala/reflect/TypeTest.scala. Making the analogous example based on dependent functions instead of SAMs passed even without this patch. I am going to include that test. I have reverted the change, since it's not clear we need it.
Various improvements to make type inference and internal checking more robust. Best reviewed commit by commit.
These all address issues that were first uncovered when trying to run the type inferencer on inferred code again, where all type variables are reset to undefined. So the program is different since it contains adaptations like implicit arguments, but the
type variables are inferred again.