Skip to content

Commit 6c52e82

Browse files
committed
fix(java): no import resolves to a generated record accessor
The import resolver's symbol-name fallback tries the trailing segments of an import path that names no project symbol, and a package segment that merely spells a record accessor bound the import to it. On elasticsearch, `import javax.crypto.spec.PBEKeySpec` bound a record's spec() accessor, and `new PBEKeySpec(...)`, annotations and type uses then followed the import onto it: 6,302 IMPORTS edges into accessors, plus CALLS, USAGE, DECORATES and THROWS through the import map. A generated member is registered by qualified name only, and no Java import can name an instance accessor, so the fallback now skips it exactly as it skips a Python def-local (DeusData#1548). The record pipeline fixture gains an import whose package segment spells an accessor. Without the change it fails in the sequential, parallel and incremental venues: an IMPORTS edge into Point.y, and make() -> Point.y. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 729ce33 commit 6c52e82

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

‎src/pipeline/pass_pkgmap.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2592,6 +2592,15 @@ static const cbm_gbuf_node_t *resolve_import_strategies(
25922592
if (import_candidate_is_python_local(ctx->gbuf, cand)) {
25932593
continue;
25942594
}
2595+
/* Nor is a generated member (a Java record's implicit
2596+
* accessor, an instance method no import can name). It is
2597+
* registered by qualified name only, and a package segment
2598+
* that merely spells it (`javax.crypto.spec` -> spec())
2599+
* must not bind the import -- or every use of the
2600+
* imported name -- to it. */
2601+
if (cbm_node_props_generated(cand->properties_json)) {
2602+
continue;
2603+
}
25952604
if (source_file_qn && cand->qualified_name &&
25962605
strcmp(cand->qualified_name, source_file_qn) == 0) {
25972606
continue; /* self */

‎tests/test_pipeline.c‎

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17374,7 +17374,12 @@ TEST(pipeline_python_nested_def_local_after_incremental_issue1548) {
1737417374
* name registry is its only route to Point.y. `data` calls x(), whose other
1737517375
* spelling is Spring's private field: neither the accessor (a name guess) nor
1737617376
* the field (a Java call never names data) is its target. The record's
17377-
* hand-written z() and norm() are source members: no `generated` mark. */
17377+
* hand-written z() and norm() are source members: no `generated` mark.
17378+
* `org.external.y.Vector` is not in the project, and its package segment `y`
17379+
* spells the accessor: the import's symbol-name fallback must not bind it
17380+
* there (no IMPORTS edge), or `new Vector()` in `make` would follow the import
17381+
* onto the accessor (elasticsearch: `import javax.crypto.spec.PBEKeySpec`
17382+
* bound a record's `spec()`). */
1737817383
static const char jgen_point_java[] =
1737917384
"package com.example;\n"
1738017385
"public record Point(double x, double y, double z) {\n"
@@ -17387,11 +17392,12 @@ static const char jgen_spring_java[] = "package com.example;\n"
1738717392
" public void put(double v) { this.x = v; }\n"
1738817393
"}\n";
1738917394
static const char jgen_caller_java[] = "package com.example;\n"
17390-
"import org.external.Vector;\n"
17395+
"import org.external.y.Vector;\n"
1739117396
"public final class Caller {\n"
1739217397
" public double near(Point p) { return p.y(); }\n"
1739317398
" public double far(Vector v) { return v.y(); }\n"
1739417399
" public double data(Vector v) { return v.x(); }\n"
17400+
" public Object make() { return new Vector(); }\n"
1739517401
"}\n";
1739617402

1739717403
/* The id of the one `label` node called `name` in `file_path`; 0 when there is
@@ -17451,6 +17457,19 @@ static int jgen_calls(cbm_store_t *s, int64_t source_id, int64_t target_id,
1745117457
return n;
1745217458
}
1745317459

17460+
/* Edges of `type` into `target_id`. */
17461+
static int jgen_edges_into(cbm_store_t *s, int64_t target_id, const char *type) {
17462+
cbm_edge_t *edges = NULL;
17463+
int ec = 0;
17464+
if (cbm_store_find_edges_by_target_type(s, target_id, type, &edges, &ec) != CBM_STORE_OK) {
17465+
return -1;
17466+
}
17467+
if (edges) {
17468+
cbm_store_free_edges(edges, ec);
17469+
}
17470+
return ec;
17471+
}
17472+
1745417473
/* One fact of jgen_check: reported, counted, and the check goes on, so a run
1745517474
* shows every fact that does not hold. */
1745617475
#define JGEN_EXPECT(cond) \
@@ -17475,8 +17494,9 @@ static int jgen_check(cbm_store_t *s, const char *project) {
1747517494
int64_t near = jgen_node(s, project, "near", "Method", "Caller.java", NULL);
1747617495
int64_t far = jgen_node(s, project, "far", "Method", "Caller.java", NULL);
1747717496
int64_t data = jgen_node(s, project, "data", "Method", "Caller.java", NULL);
17497+
int64_t make = jgen_node(s, project, "make", "Method", "Caller.java", NULL);
1747817498
JGEN_EXPECT(acc_x > 0 && acc_y > 0 && own_z > 0 && norm > 0);
17479-
JGEN_EXPECT(near > 0 && far > 0 && data > 0);
17499+
JGEN_EXPECT(near > 0 && far > 0 && data > 0 && make > 0);
1748017500
/* The compiler's members are marked; the hand-written ones are not. */
1748117501
JGEN_EXPECT(gen_x);
1748217502
JGEN_EXPECT(gen_y);
@@ -17489,6 +17509,9 @@ static int jgen_check(cbm_store_t *s, const char *project) {
1748917509
JGEN_EXPECT(jgen_calls(s, far, 0, "y") == 0);
1749017510
/* Neither the accessor nor Spring's field `x`. */
1749117511
JGEN_EXPECT(jgen_calls(s, data, 0, "x") == 0);
17512+
/* No import names a generated member, so nothing follows one onto it. */
17513+
JGEN_EXPECT(jgen_edges_into(s, acc_y, "IMPORTS") == 0);
17514+
JGEN_EXPECT(jgen_calls(s, make, 0, "y") == 0);
1749217515
return failed;
1749317516
}
1749417517
#undef JGEN_EXPECT

0 commit comments

Comments
 (0)