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

Types of lambda parameters are lost in some cases #317

Open
Juuxel opened this issue Sep 9, 2023 · 0 comments
Open

Types of lambda parameters are lost in some cases #317

Juuxel opened this issue Sep 9, 2023 · 0 comments
Labels
bug Something isn't working Priority: Medium Medium priority Subsystem: Writing Anything concerning how expressions are written

Comments

@Juuxel
Copy link
Contributor

Juuxel commented Sep 9, 2023

See also: #308

This seemingly happens when the outside context (such as a local variable or parameter type) doesn't require the more specific type provided in the original source code. Dropping the types does, however, lead to compilation errors and silent behaviour changes.

Example

(from the test added in #308)

Input code:

Function<?, ?> f2a = (String x) -> x;
Function<?, ?> f2b = (String x) -> x.length() + 1;

// g(Function<?, ?>)
g((String x) -> x);
g((String x) -> x.length() + 1);

Decompiled output:

Function<?, ?> f2a = x -> x; // behaviour change
Function<?, ?> f2b = x -> x.length() + 1; // compilation error
this.g(x -> x); // behaviour change
this.g(x -> x.length() + 1); // compilation error

// The behaviour change is that the lambda now accepts any object, instead of throwing
// a ClassCastException if a non-String value is passed to it.
// The compilation error comes from trying to use String methods on a general Object instance.
@jaskarth jaskarth added bug Something isn't working Subsystem: Writing Anything concerning how expressions are written Priority: Medium Medium priority labels Sep 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Priority: Medium Medium priority Subsystem: Writing Anything concerning how expressions are written
Projects
None yet
Development

No branches or pull requests

2 participants