You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "Daniel Sun (Jira)" <ji...@apache.org> on 2024/12/01 05:07:00 UTC
[jira] [Updated] (GROOVY-11525) Support expression scope variable
[ https://issues.apache.org/jira/browse/GROOVY-11525?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Daniel Sun updated GROOVY-11525:
--------------------------------
Description:
Let's take a look at the following code first:
{code}
int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
{code}
variable {{h}} is actually an expression scope variable, but current syntax doesn't support.
I propose an expression scope variable syntax, e.g.
{code}
int hash(Object key) {
// h is only visible in the expression
return (int h; (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16))
}
{code}
We can reduce the scope of {{h}} further:
{code}
int hash(Object key) {
// h is only visible in the expression
return (key == null) ? 0 : (int h; (h = key.hashCode()) ^ (h >>> 16))
}
{code}
was:
Let's take a look at the following code first:
{code}
int hash(Object key) {
int h;
return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
}
{code}
variable {{h}} is actually an expression scope variable, but current syntax doesn't support.
I propose an expression scope variable syntax, e.g.
{code}
int hash(Object key) {
// h is only visible in the expression
return (int h; (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16))
}
{code}
> Support expression scope variable
> ---------------------------------
>
> Key: GROOVY-11525
> URL: https://issues.apache.org/jira/browse/GROOVY-11525
> Project: Groovy
> Issue Type: New Feature
> Reporter: Daniel Sun
> Priority: Major
>
> Let's take a look at the following code first:
> {code}
> int hash(Object key) {
> int h;
> return (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16);
> }
> {code}
> variable {{h}} is actually an expression scope variable, but current syntax doesn't support.
> I propose an expression scope variable syntax, e.g.
> {code}
> int hash(Object key) {
> // h is only visible in the expression
> return (int h; (key == null) ? 0 : (h = key.hashCode()) ^ (h >>> 16))
> }
> {code}
> We can reduce the scope of {{h}} further:
> {code}
> int hash(Object key) {
> // h is only visible in the expression
> return (key == null) ? 0 : (int h; (h = key.hashCode()) ^ (h >>> 16))
> }
> {code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)