-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Type parameter clause inference for lambdas (and method references via eta-expansion) #18169
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
298eb0d
to
fc0476f
Compare
When a lambda is written without a type parameter clause but the expected type is a polymorphic function type, try to adapt the lambda into a polymorphic lambda by inferring an appropriate type parameter clause. This change broke one example in spire which relied on implicit conversions. The fix has been accepted upstream: typelevel/spire#1247
In that case, let eta-expansion produce an untyped monomorphic lambda as usual. Thanks to the previous commit, a type parameter clause for this lambda will be inferred if possible.
fc0476f
to
183d84e
Compare
One presentation compiler test broke:
Error: Test dotty.tools.pc.tests.completion.CompletionKeywordSuite.type-template failed: java.lang.AssertionError:
Error: Code snippet:
Error:
Error: package foo
Error:
Error: class Foo {
Error: typ@@
Error: }
Error:
Error:
Error: (+++ Expected, --- Obtained, NO CHANGES)
Error:
Error: - typeClauseInference - scala.runtime.stdLibPatches.language.experimental
Error: type
Error:
Error: , took 0.017 sec
@rochala How does auto-completion decide which packages to look into? We should blacklist scala.runtime because it's only supposed to be called from compiler-generated code.
Hey, so basically this completion is provided from the indexed sources. It indexes whole classpath. If you want to add it to blacklist, it should happen in the symbol search visitor class https://github.com/rochala/dotty/blob/36fdbc5f6f695371fbc64cbcaac80c91f3fa5bc4/presentation-compiler/src/main/dotty/tools/pc/completions/Completions.scala#L559-L595
You may also try to ignore it during indexing. It is up to you.
If we ignore filter globally, it won't be included even in completions from scope, which is undesired.
Uh oh!
There was an error while loading. Please reload this page.
This PR implements type parameter clause inference which lets us write a regular lambda where a polymorphic function type is expected:
Additionally, we also allow regular eta-expansion (which adapts a method reference
foo
into an untyped lambdax => foo(x)
) to proceed when the expected type is a polymorphic function type, the untyped lambda can then be adapted into a polymorphic lambda by type parameter clause inference:This is similar to the proposed SIP-49 but instead of inferring the type parameter clause from the method reference we end up inferring it from the expected type, which means we allow the method reference and expected type to have different numbers of type parameters:
TODO: