Skip to content

GROOVY-9892: fix operand stack for ++x / x++ in static compilation#1455

Merged
daniellansun merged 1 commit intoapache:GROOVY_3_0_Xfrom
Fiouz:GROOVY-9892
Jan 15, 2021
Merged

GROOVY-9892: fix operand stack for ++x / x++ in static compilation#1455
daniellansun merged 1 commit intoapache:GROOVY_3_0_Xfrom
Fiouz:GROOVY-9892

Conversation

@Fiouz
Copy link
Copy Markdown
Contributor

@Fiouz Fiouz commented Jan 14, 2021

40ee3fd replaced an invocation of
ScriptBytecodeAdapter.setGroovyObjectProperty() into an invocation of
the generated pfaccess$0* mutator method.
Contrary to setGroovyObjectProperty(), the mutator method has a return
value, which ends up pushed to the operand stack.

This commit discards the value being pushed to the stack by pop'ing it.

@@ -0,0 +1,21 @@
package org.codehaus.groovy.classgen.asm.sc.bugs
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

license header is expected here:

/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

License header is now added

}.call()
}
}
assert new OuterClass().call() == 'Hello1World'
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add a test case to cover counter++ ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test modified to verify both prefix and postfix increment

@daniellansun
Copy link
Copy Markdown
Contributor

LGTM

40ee3fd replaced an invocation of
`ScriptBytecodeAdapter.setGroovyObjectProperty()` into an invocation of
the generated `pfaccess$0*` mutator method.
Contrary to `setGroovyObjectProperty()`, the mutator method has a return
value, which ends up pushed to the operand stack.

This commit discards the value being pushed to the stack by pop'ing it.
@daniellansun
Copy link
Copy Markdown
Contributor

Merged. Thanks!

@daniellansun daniellansun reopened this Jan 15, 2021
@daniellansun daniellansun merged commit fb10429 into apache:GROOVY_3_0_X Jan 15, 2021
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.

2 participants