Skip to content
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

fixed the FieldWrite bug in OperatorAssignment #487

Merged
merged 1 commit into from
Jan 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2763,7 +2763,7 @@ public boolean visit(QualifiedNameReference qualifiedNameReference, BlockScope s
int sourceStart = (int) (positions[0] >>> 32);
for (FieldBinding b : qualifiedNameReference.otherBindings) {
CtFieldAccess<Object> other;
if (qualifiedNameReference.otherBindings.length == i + 1 && context.stack.peek().element instanceof CtAssignment) {
if (qualifiedNameReference.otherBindings.length == i + 1 && context.stack.peek().element instanceof CtAssignment && context.assigned) {
other = factory.Core().createFieldWrite();
} else {
other = factory.Core().createFieldRead();
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/spoon/test/fieldaccesses/BUG20160112.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package spoon.test.fieldaccesses;

public class BUG20160112 {
BUG20160112 a;
int us;

public void test() {
int z = 0;
z += a.us;
return;
}
}
16 changes: 15 additions & 1 deletion src/test/java/spoon/test/fieldaccesses/FieldAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import org.junit.Test;
import spoon.Launcher;
import spoon.reflect.code.CtArrayWrite;

import spoon.reflect.code.CtExpression;
import spoon.reflect.code.CtFieldAccess;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtFieldWrite;
Expand All @@ -11,7 +13,7 @@
import spoon.reflect.code.CtUnaryOperator;
import spoon.reflect.code.CtVariableWrite;
import spoon.reflect.code.UnaryOperatorKind;
import spoon.reflect.declaration.CtElement;
import spoon.reflect.code.CtOperatorAssignment;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtMethod;
import spoon.reflect.declaration.CtType;
Expand All @@ -28,6 +30,7 @@

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static spoon.test.TestUtils.build;

Expand Down Expand Up @@ -123,6 +126,17 @@ public void testBCUBug20140402() throws Exception {

}

@Test
public void testBUG20160112() throws Exception {
CtType<?> type = build("spoon.test.fieldaccesses", "BUG20160112");
assertEquals("BUG20160112", type.getSimpleName());
CtOperatorAssignment<?, ?> ass = type.getElements(
new TypeFilter<CtOperatorAssignment<?,?>>(CtOperatorAssignment.class)).get(0);
assertNotNull("z+=a.us", ass);
CtExpression<?> righthand = ass.getAssignment();
assertTrue("a.us should be CtFieldRead", righthand instanceof CtFieldRead);
}

@Test
public void testTargetedAccessPosition() throws Exception{
CtType<?> type = build("spoon.test.fieldaccesses", "TargetedAccessPosition");
Expand Down