Repository navigation
fix(java): a call reaches the same-named class the calling file can see - #3347
Merged
Merged
Conversation
colbymchenry
force-pushed
the
claude/issue-2976-java-class-visibility
branch
9 times, most recently
from
November 18, 2026 06:13
16f94a2 to
41ce332
Compare
With com.x.a.Util and com.x.b.Util both in a project, a Java call under
`import com.x.b.*;` went to whichever Util was indexed first:
- `Util.log("x")`: the class strategy took every class named Util with no
check of what the file can see (C#, VB.NET and PHP had one, Java none);
- `Util u = new Util(); u.run()`: the declared type was pinned only by an
explicit import, and the import mappings skip on-demand imports;
- `new Util().run()`: same gap, so no class was chosen and no edge made;
- `com.x.b.Util.log("q")`: the package was never read, and the method
was guessed by its name, whatever the file imported.
javaClassInScope now finds the class a simple name means in a file the
way javac does: the file's own top-level type, a single-type import, the
file's package, then the packages its on-demand imports name. Two
on-demand packages that both supply the name make it ambiguous, which
javac rejects, so such a call links nothing. It feeds the class strategy
(matchMethodCall), the declared-type pin (javaTypeRef), importedFqnOf
(the chained `new` and the other typed paths) and
matchJavaCsharpNewReceiverCall, which now matches a class by its fully
qualified name before its path. javaQualifiedReceiverType reads a
receiver written with its package, `com.x.b.Util` or
`com.x.c.Outer.Inner`, as that type. It decides nothing when a nested
type shares the name, or a step holds copies of one fully qualified
name, leaving those to the existing rules.
Validation: java-class-visibility.test.ts fails on main (4 of 5) and
passes with the fix; the 40 Java, Kotlin, Scala, Spring and Play test
files pass. A/B against v1.6.3 (147fe29): jsoup 2 calls, an
elasticsearch subtree (server action, cluster, common: 1,710 files) 60
calls keep their target and now resolve through the class they name
(fully qualified receivers and enum constants' types, 0.65 to 0.85),
TheAlgorithms/Java (1,693 files) unchanged; no edge moved, appeared or
went. nowinandroid (Kotlin) and gin (Go) dumps byte-identical. Index
time on the elasticsearch subtree, median of 3 interleaved: 34.3 s on
main, 31.9 s with the fix.
Fixes #2976
Fixes #3290
Fixes #3291
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
colbymchenry
force-pushed
the
claude/issue-2976-java-class-visibility
branch
from
November 18, 2026 06:15
41ce332 to
88632f1
Compare
This was referenced Nov 18, 2026
inth3shadows
added a commit
to inth3shadows/codegraph
that referenced
this pull request
Nov 18, 2026
Upstream landed our colbymchenry#3330 (b286279), colbymchenry#3278 (df20853) and colbymchenry#3249, plus its own fixes for issues the fork carried: Python typing.overload (colbymchenry#3349, colbymchenry#3216's approach), Java wildcard visibility (colbymchenry#3347), colbymchenry#3272 (colbymchenry#3364), colbymchenry#2951/colbymchenry#2953. Conflicts: - name-matcher.ts: upstream's side for Rust (colbymchenry#3381-colbymchenry#3384) and Java (colbymchenry#3347). The fork keeps its module-receiver check (namespace-only defaults, a default that is a module's own function) and adds upstream's colbymchenry#2951 clause and isImportedFunctionReceiver guard. Upstream's colbymchenry#3272 block (a module default made with `new`) runs first, but defers when the module exports the name or its exports can't be read for certain, so the fork's alias edges stay. A parameter or local shadowing the binding is the receiver (colbymchenry#2953). - import-resolver.ts: upstream's member-of-imported-function block, then the fork's guard for the remaining cases (default imports), excluding call/apply/bind. - python-overloads.ts, index.ts: upstream's (duplicate memo clear dropped). - module-importers.ts, workspace-packages.ts: both imports. - CHANGELOG: upstream's [Unreleased] plus the fork's PHP line (colbymchenry#3327). Tests: member-call-not-receiver's static-property case now expects User::all (upstream colbymchenry#3380 indexes `User.all = function` as a static method). parse-deadline's two wasm-hang cases are skipped on the fork: its patched runtime (tree-sitter#5997) parses the input instead of hanging. README: colbymchenry#3249, colbymchenry#3278, colbymchenry#3330, colbymchenry#3216 and colbymchenry#3138 moved to "now in upstream". Checks: tsc 0; suite 11415 passed, 2 failed before the parse-deadline gate (both from the patched runtime); fork-only and upstream colbymchenry#3272/colbymchenry#3380 tests pass.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When two packages declare a Java class of the same name (
com.x.a.Util,com.x.b.Util), a call now reaches the one the calling file can see, the way javac looks the name up: the file's own type, a single-type import, the file's package, then its on-demand (.*) imports. A receiver written with its package,com.x.b.Util.log(…), is read as that class. A name two on-demand imports both supply is ambiguous (javac rejects it), so such a call links nothing.Fixes #2976
Fixes #3290
Fixes #3291
Root cause
Under
import com.x.b.*;the first-indexedUtilwon in three separate paths, and a fourth ignored the package:Util.log("x")(Java: a static call through a wildcard import resolves to a same-named class in an unimported package #2976): the class strategy inmatchMethodCalltook every class namedUtil; C#, VB.NET and PHP reorder those by what the file can see, Java didn't.Util u = new Util(); u.run()(Java: a call through a typed local ignores a wildcard import and links to an unimported class #3291):javaTypeRefpinned the declared type only through an explicit import, and the import mappings skip on-demand imports.new Util().run()(Java: a static call through a wildcard import resolves to a same-named class in an unimported package #2976):matchJavaCsharpNewReceiverCallread the class fromimportedFqnOf, which had the same gap, so it chose nothing and made no edge.com.x.b.Util.log("q")(Java: a fully qualified static call links to a same-named class in another package #3290): no strategy read the package; the method was guessed by its name.Fix (
src/resolution/name-matcher.ts)javaClassInScope(name, file): javac's order over the project's top-level classes of the name. Null for two on-demand packages (ambiguous); undefined (existing rules decide) when a nested type shares the name or one step holds copies of one fully qualified name.javaQualifiedReceiverType(written): the lowercase segments before the first capitalized one are the package (com.x.b+Util,com.x.c+Outer.Inner), looked up by qualified name.javaTypeRef's declared-type pin,importedFqnOf(Java only) and the typed-receiver pin, andmatchJavaCsharpNewReceiverCall, which now matches a class by its fully qualified name before its path.Validation
__tests__/java-class-visibility.test.ts(5 tests): the static call and chainednewunder a wildcard (Java: a static call through a wildcard import resolves to a same-named class in an unimported package #2976), the typed local (Java: a call through a typed local ignores a wildcard import and links to an unimported class #3291), the qualified call under each import plus a nested qualified type (Java: a fully qualified static call links to a same-named class in another package #3290), javac's order (own package before a wildcard, a single-type import before both), and the ambiguous double wildcard. 4 of 5 fail on main; all pass with the fix.ffaaf6f2).147fe290), sites grouped by call:org.jsoup.Jsoup.parse, 0.65 → 0.85)serveraction + cluster + common (edac141f)These repos don't combine project wildcard imports with duplicate class names; the tests cover that.
Contributor PRs
PRs #3138 and #3139 by @johnhldiver-beep each target half of #2976 (the static call and the chained
new). This change is written from the issues and also covers #3290 and #3291 and the ambiguous case; credited in the CHANGELOG.🤖 Generated with Claude Code