[code-reflection] RFR: Disallow `null` return expressions in quoted lambdas
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Jul 8 12:12:34 UTC 2025
Lambda expressions that are turned into a `Quoted` instance don't have an associated functional interface. Instead, they are type checked bottom-up (the parameter types in such lambdas must be explicit), and the return type is inferred from the various return expressions in the lambda body.
The aim of this patch is to establish a similar set of rules between quoted lambda return expressions and expressions that are allowed on the RHS of a `var`. More specifically, the RHS of a `var` is restricted as follows:
1. can't be `null`
2. can't be a "naked" array initializer, e.g. `{ 1, 2, 3 }`
3. can't be a poly expression (a lambda, or a method reference)
Now, (2) and (3) are already taken care of. (2) is not allowed in return context, and (3) is already rejected, given the body of the quoted lambda is attributed w/o a target type.
So this PR adds a check for (1), to reject `null` return expressions.
There are some other quality-of-life changes to make sure the compiler doesn't generate spurious diagnostics in case of errors.
I've beefed up the test a bit. First, I've added tests to make sure that invalid return expressions in quoted lambdas are correctly rejected, regardless of whether the quoted lambda appears in assignment vs. method vs. generic method context.
Secondly, I've added an IR test to make sure that the inferred return type of a quoted lambda is correctly upward-projected, to get rid of any non-denotable type that might arise in the inference process.
-------------
Commit messages:
- Initial push
Changes: https://git.openjdk.org/babylon/pull/489/files
Webrev: https://webrevs.openjdk.org/?repo=babylon&pr=489&range=00
Stats: 198 lines in 11 files changed: 179 ins; 9 del; 10 mod
Patch: https://git.openjdk.org/babylon/pull/489.diff
Fetch: git fetch https://git.openjdk.org/babylon.git pull/489/head:pull/489
PR: https://git.openjdk.org/babylon/pull/489
More information about the babylon-dev
mailing list