Skip to content

Commit df87dda

Browse files
committed
Fix Inconsistent Qualified Names
1 parent 850ffbf commit df87dda

4 files changed

Lines changed: 12 additions & 8 deletions

File tree

liquidjava-example/src/main/java/testSuite/classes/conflicting_ghost_names_correct/SimpleTest.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ public void example() {
1010
list.get(0);
1111

1212
Stack<Integer> stack = new Stack<>();
13-
stack.push(1);
14-
stack.peek();
13+
if (stack.empty()) {
14+
stack.push(1);
15+
}
1516
stack.pop();
1617
}
1718
}

liquidjava-example/src/main/java/testSuite/classes/conflicting_ghost_names_correct/StackRefinements.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import liquidjava.specification.ExternalRefinementsFor;
44
import liquidjava.specification.Ghost;
5+
import liquidjava.specification.Refinement;
56
import liquidjava.specification.StateRefinement;
67

78
@ExternalRefinementsFor("java.util.Stack")
@@ -18,4 +19,7 @@ public interface StackRefinements<E> {
1819

1920
@StateRefinement(from="size(this) > 0")
2021
public E peek();
22+
23+
@Refinement("_ ? size(this) == 0 : size(this) > 0")
24+
public boolean empty();
2125
}

liquidjava-verifier/src/main/java/liquidjava/processor/refinement_checker/TypeChecker.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,9 @@ public Optional<Predicate> getRefinementFromAnnotation(CtElement element) throws
105105
}
106106
}
107107
if (ref.isPresent()) {
108-
Predicate p = new Predicate(ref.get(), element);
108+
String prefix = getQualifiedClassName(element);
109+
Predicate p = prefix == null ? new Predicate(ref.get(), element)
110+
: new Predicate(ref.get(), element, prefix);
109111
if (!p.getExpression().isBooleanExpression()) {
110112
SourcePosition position = Utils.getLJAnnotationPosition(element, ref.get());
111113
throw new InvalidRefinementError(position, "Refinement predicate must be a boolean expression",

liquidjava-verifier/src/main/java/liquidjava/rj_language/ast/FunctionInvocation.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ public int hashCode() {
9393
final int prime = 31;
9494
int result = 1;
9595
result = prime * result + ((getArgs() == null) ? 0 : getArgs().hashCode());
96-
result = prime * result + ((name == null) ? 0 : Utils.getSimpleName(name).hashCode()); // same here
96+
result = prime * result + ((name == null) ? 0 : name.hashCode());
9797
return result;
9898
}
9999

@@ -114,10 +114,7 @@ public boolean equals(Object obj) {
114114
if (name == null) {
115115
return other.name == null;
116116
} else {
117-
// prefixes are inconsistent for refined class ghost calls: some use the
118-
// original class prefix, others use the caller class prefix
119-
// for now we compare simple names, but prefix handling should be fixed instead of having this workaround
120-
return other.name != null && Utils.getSimpleName(name).equals(Utils.getSimpleName(other.name));
117+
return name.equals(other.name);
121118
}
122119
}
123120
}

0 commit comments

Comments
 (0)