-
Notifications
You must be signed in to change notification settings - Fork 53
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
feat(ast): add support for LambdaExpr to infer type from return expr type #1011
Conversation
Looks a good feature improvement. If I'm understanding correctly, we cannot assign a lambda expression to a variable before this change because the return type is always |
Yes, the improvement is exactly as you described. |
// which would enable assignment to an appropriate variable. | ||
return TypeNode.VOID; | ||
} | ||
public abstract TypeNode type(); |
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.
keeping this despite sonar complains about already defined in Expr
interface. It's seems the recommend way for @autovalue as explained in this doc. Also keeps consistent with other expression classes like ValueExpr
, CastExpr
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.
You might already considered it, can we just implement the type()
method to return the type of ReturnExpr
, like return returnExpr().expr().type()
? So that we don't have to change any of the code in the builder.
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.
hmm, I actually did not think of that. Sounds like a better idea with less changes to existing code. The only thing is we won't be able to set a default value for type()
, but that should be fine because ReturnExpr().expr()
should always have type
associated.
Let me make the changes.
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.
If you want, we can still expose the setType()
method and set a default value in the builder()
method, but like you said ReturnExpr().expr()
should always have type
associated so we should never call setType()
explicitly.
Kudos, SonarCloud Quality Gate passed! |
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.
LGTM
🤖 I have created a release *beep* *boop* --- ## [2.9.0](v2.8.3...v2.9.0) (2022-07-11) ### Features * **ast:** add support for LambdaExpr to infer type from return expr type ([#1011](#1011)) ([a179558](a179558)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…type (#1011) This will enable it to be assigned to an appropriate variable Before this change: cannot assign a lambda expression to a variable because its type is always VOID. After this change: lambda expression builder will infer type from returnExpr’s expression type. Allowing it to be assigned to an appropriate variable. Because returnExpr is a required field, its type should always be accessible. Example: a naive sample usage is provided in JavaWriterVisitorTest.java as test.
🤖 I have created a release *beep* *boop* --- ## [2.9.0](v2.8.3...v2.9.0) (2022-07-11) ### Features * **ast:** add support for LambdaExpr to infer type from return expr type ([#1011](#1011)) ([b24892d](b24892d)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please).
…o v2.0.1 (#1011) [![Mend Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com) This PR contains the following updates: | Package | Change | Age | Adoption | Passing | Confidence | |---|---|---|---|---|---| | [com.google.api-client:google-api-client-bom](https://togithub.com/googleapis/google-api-java-client/tree/master/google-api-client-bom) ([source](https://togithub.com/googleapis/google-api-java-client)) | `2.0.0` -> `2.0.1` | [![age](https://badges.renovateapi.com/packages/maven/com.google.api-client:google-api-client-bom/2.0.1/age-slim)](https://docs.renovatebot.com/merge-confidence/) | [![adoption](https://badges.renovateapi.com/packages/maven/com.google.api-client:google-api-client-bom/2.0.1/adoption-slim)](https://docs.renovatebot.com/merge-confidence/) | [![passing](https://badges.renovateapi.com/packages/maven/com.google.api-client:google-api-client-bom/2.0.1/compatibility-slim/2.0.0)](https://docs.renovatebot.com/merge-confidence/) | [![confidence](https://badges.renovateapi.com/packages/maven/com.google.api-client:google-api-client-bom/2.0.1/confidence-slim/2.0.0)](https://docs.renovatebot.com/merge-confidence/) | --- ### Release Notes <details> <summary>googleapis/google-api-java-client</summary> ### [`v2.0.1`](https://togithub.com/googleapis/google-api-java-client/blob/HEAD/CHANGELOG.md#​201-httpsgithubcomgoogleapisgoogle-api-java-clientcomparev200v201-2022-11-05) [Compare Source](https://togithub.com/googleapis/google-api-java-client/compare/v2.0.0...v2.0.1) ##### Bug Fixes - Add error description to batch emptiness validation ([#​2109](https://togithub.com/googleapis/google-api-java-client/issues/2109)) ([2668dd1](https://togithub.com/googleapis/google-api-java-client/commit/2668dd1348e7710a83e008b1e2b2ff6fceedfedf)) - **deps:** Update dependency com.google.api-client:google-api-client to v2 ([#​2108](https://togithub.com/googleapis/google-api-java-client/issues/2108)) ([570a162](https://togithub.com/googleapis/google-api-java-client/commit/570a1625fbb3806961d328d90d784b5f0ed21a0c)) - **deps:** Update dependency com.google.appengine:appengine-api-1.0-sdk to v2.0.10 ([#​2174](https://togithub.com/googleapis/google-api-java-client/issues/2174)) ([9077b4a](https://togithub.com/googleapis/google-api-java-client/commit/9077b4ae4c4214cb0fdcb5248f8c7ecbeb51d27f)) - **deps:** Update dependency com.google.appengine:appengine-api-1.0-sdk to v2.0.6 ([#​2124](https://togithub.com/googleapis/google-api-java-client/issues/2124)) ([51adc54](https://togithub.com/googleapis/google-api-java-client/commit/51adc541819284dabcdefef39fa39b4a0bd13f6a)) - **deps:** Update dependency com.google.appengine:appengine-api-1.0-sdk to v2.0.7 ([#​2131](https://togithub.com/googleapis/google-api-java-client/issues/2131)) ([6892bb2](https://togithub.com/googleapis/google-api-java-client/commit/6892bb293ca578b793fe0024c884b21e675abd45)) - **deps:** Update dependency com.google.appengine:appengine-api-1.0-sdk to v2.0.8 ([#​2140](https://togithub.com/googleapis/google-api-java-client/issues/2140)) ([bb6f19c](https://togithub.com/googleapis/google-api-java-client/commit/bb6f19ce2a89f6d419c908eff7faa944ea74799e)) - **deps:** Update dependency com.google.cloud:libraries-bom to v26.1.0 ([#​2126](https://togithub.com/googleapis/google-api-java-client/issues/2126)) ([3d0e0ff](https://togithub.com/googleapis/google-api-java-client/commit/3d0e0ff57cde5ca9eb56e5266dc5c37f3777179d)) - **deps:** Update dependency com.google.cloud:libraries-bom to v26.1.1 ([#​2134](https://togithub.com/googleapis/google-api-java-client/issues/2134)) ([15ce062](https://togithub.com/googleapis/google-api-java-client/commit/15ce06244a06b64545f145a2ebdfb62863fcbad4)) - **deps:** Update dependency com.google.cloud:libraries-bom to v26.1.2 ([#​2143](https://togithub.com/googleapis/google-api-java-client/issues/2143)) ([da2f6f3](https://togithub.com/googleapis/google-api-java-client/commit/da2f6f3e4645ff3b84465943833404526077ad20)) </details> --- ### Configuration 📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined). 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate](https://www.mend.io/free-developer-tools/renovate/). View repository job log [here](https://app.renovatebot.com/dashboard#github/googleapis/java-core). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNy4xIiwidXBkYXRlZEluVmVyIjoiMzQuMTcuMSJ9-->
🤖 I have created a release *beep* *boop* --- ## [2.8.26](https://togithub.com/googleapis/java-core/compare/v2.8.25...v2.8.26) (2022-11-07) ### Dependencies * Update dependency com.google.api-client:google-api-client-bom to v2.0.1 ([#1011](https://togithub.com/googleapis/java-core/issues/1011)) ([bbcaed9](https://togithub.com/googleapis/java-core/commit/bbcaed9a9688a054adbb8d4615af14566b98a297)) * Update dependency com.google.api.grpc:proto-google-common-protos to v2.10.0 ([#1010](https://togithub.com/googleapis/java-core/issues/1010)) ([1f41e6b](https://togithub.com/googleapis/java-core/commit/1f41e6b9bf86ea94dbd0efda348d46f04e62baa4)) * Update dependency com.google.api.grpc:proto-google-iam-v1 to v1.6.7 ([#1005](https://togithub.com/googleapis/java-core/issues/1005)) ([aac06c2](https://togithub.com/googleapis/java-core/commit/aac06c231ae59e4e913a228328202bdceda39ec4)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
This will enable it to be assigned to an appropriate variable
Before this change: cannot assign a lambda expression to a variable because its type is always
VOID
.After this change: lambda expression builder will infer type from
returnExpr
’s expression type. Allowing it to be assigned to an appropriate variable. BecausereturnExpr
is a required field, its type should always be accessible.Example: a naive sample usage is provided in JavaWriterVisitorTest.java as test. Another example is what I am trying to generate for spring autoconfig code:
this.projectIdProvider = () -> clientProperties.getProjectId();
. Ideally through method reference, but lambda assignment does the same thing and it’s an easier feature addition.