Skip to content

Commit 2ca1204

Browse files
committed
Correct 'AnalysisUnit.equals' method
Before this commit, in the 'AnalysisUnit.equals' method, the other value was compared with itself, resulting in the method returning always true. Now 'other' is compared to 'this'.
1 parent f4904d0 commit 2ca1204

File tree

4 files changed

+21
-1
lines changed

4 files changed

+21
-1
lines changed

langkit/templates/java_api/main_class.mako

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3605,7 +3605,7 @@ public final class ${ctx.lib_name.camel} {
36053605
if(this == o) return true;
36063606
if(!(o instanceof AnalysisUnit)) return false;
36073607
final AnalysisUnit other = (AnalysisUnit) o;
3608-
return other.reference.equals(other.reference);
3608+
return this.reference.equals(other.reference);
36093609
}
36103610

36113611
}

testsuite/tests/java_api/general/common/BindingsTests.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,20 @@ private static void testUnitFileName() {
114114
) {
115115
// Get the unit for the foo.txt file
116116
AnalysisUnit unit = context.getUnitFromFile("foo.txt");
117+
AnalysisUnit other = context.getUnitFromFile("foo.txt");
118+
AnalysisUnit notSame =
119+
context.getUnitFromBuffer("var identifier", "bar.txt");
120+
System.out.println(
121+
unit.toString() + " != " + other + " = " + (unit != other)
122+
);
123+
System.out.println(
124+
unit.toString() + ".equals(" + other + ") = " +
125+
unit.equals(other)
126+
);
127+
System.out.println(
128+
unit.toString() + ".equals(" + notSame +
129+
") = " + unit.equals(notSame)
130+
);
117131
System.out.println(
118132
"Unit for the file " +
119133
new File(unit.getFileName()).getName()

testsuite/tests/java_api/general/graal_c_api/test.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Expected '(', got Identifier at <1:5-1:15>
66
-------------------
77

88
--- Unit Filename ---
9+
<AnalysisUnit "foo.txt"> != <AnalysisUnit "foo.txt"> = true
10+
<AnalysisUnit "foo.txt">.equals(<AnalysisUnit "foo.txt">) = true
11+
<AnalysisUnit "foo.txt">.equals(<AnalysisUnit "bar.txt">) = false
912
Unit for the file foo.txt
1013
---------------------
1114

testsuite/tests/java_api/general/jni/test.out

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ Expected '(', got Identifier at <1:5-1:15>
66
-------------------
77

88
--- Unit Filename ---
9+
<AnalysisUnit "foo.txt"> != <AnalysisUnit "foo.txt"> = true
10+
<AnalysisUnit "foo.txt">.equals(<AnalysisUnit "foo.txt">) = true
11+
<AnalysisUnit "foo.txt">.equals(<AnalysisUnit "bar.txt">) = false
912
Unit for the file foo.txt
1013
---------------------
1114

0 commit comments

Comments
 (0)