Skip to content

Fix 25830 Inference of Capture-Polymorphic Lambdas v3#25905

Closed
bracevac wants to merge 6 commits intoscala:mainfrom
dotty-staging:ob/fix-25830-safe-lambdas
Closed

Fix 25830 Inference of Capture-Polymorphic Lambdas v3#25905
bracevac wants to merge 6 commits intoscala:mainfrom
dotty-staging:ob/fix-25830-safe-lambdas

Conversation

@bracevac
Copy link
Copy Markdown
Contributor

Fix #25830

Supersedes #25853

This changeset fixes cases where the compiler forgot capture information while inferring the type of capture-polymorphic lambdas, especially lambdas like [C^] => (x: File^{C}) => ....

The main idea is to keep capture parameters when they are part of the lambda’s actual type. At the same time, it avoids keeping ordinary local values too precisely in inferred type arguments, because that can hide real leaks.

It also teaches lambda checking to use the expected result type in more cases.

How much have you relied on LLM-based tools in this contribution?

Extensively, for fun.

How was the solution tested?

New automated tests (including the issue's reproducer, if applicable)

Originally added in scala#24560 to strip inferred retains from inlined call
trees before they reach the pickler. The cc setup pipeline now handles
retains correctly without this preemptive strip, and removing it
leaves scala3-bootstrapped/testCompilation green.
Fixes scala#25830. Covers plain poly lambdas, curried lambdas, mixed
outer/local scopes, capset type members, and bounded polymorphism
(see tests/pos-custom-args/captures/i25830*).
@bracevac bracevac force-pushed the ob/fix-25830-safe-lambdas branch from 8c4736e to 4f2f871 Compare April 24, 2026 16:39
@bracevac
Copy link
Copy Markdown
Contributor Author

Superseded by #25936

@bracevac bracevac closed this Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CC: Type inference for capture-polymorphic lambdas is broken

2 participants