Skip to content

Import graph (Kotlin): an import of a top-level property resolves to the file that declares it - #3749

Merged
squid-protocol merged 1 commit into
mainfrom
claude/kotlin-property-imports-3660
Sep 26, 2026
Merged

squid-protocol merged 1 commit into
mainfrom
claude/kotlin-property-imports-3660

Conversation

@squid-protocol

Copy link
Copy Markdown
Owner

Summary

Fixes #3660: its Kotlin shape, the last one left after #3743. Part of #3641.

#3596 resolves a Kotlin import a.b.name to the file that declares name under a directory matching a/b. Its declaration index held only functions and classes, so imports of top-level properties resolved to nothing. On square/kotlinpoet that's 17 imports, such as import com.squareup.kotlinpoet.metadata.isPrimary for internal val KmConstructor.isPrimary: Boolean in metadata/util.kt.

Changes:

  • kotlin _declaration_capture, a helper key registered in signal_contracts.HELPER_KEYS. It matches unindented top-level val/var names (members of a class or object are indented), and allows:

    • any receiver: KmType?., <T> List<T>.;
    • annotations first, including use-site targets like @get:JvmName("x");
    • modifiers first, but never private, which no other file can import and which would only add false ambiguity.

    Group 1 is the name, and every quantifier is bounded.

  • The scan worker runs it over prism's code stream, so commented-out code is never indexed, and records the matches as the file's declared_names.

  • The resolver (_build_resolution_map) indexes declared_names beside functions and classes for declaration-import languages.

  • Persistence: file_data.declared_names stores a JSON list, NULL when the file declares none. It's added to the CREATE statement, the upgrade guard for existing databases, and the INSERT, and the rehydrator restores it. An unchanged file's properties therefore still resolve imports on a delta scan, following the Delta scan (--incremental) is broken: silent full-scan fallback masks partial persistence + signal drift #3220 raw_imports precedent. A test round-trips it.

  • docs/signal_contracts.md is re-rendered for the new helper key.

Type of change

  • Bug fix
  • New feature / language support
  • Parsing or engine logic (gitgalaxy/core/detector.py, language_standards.py, prism.py, or a per-language rule)
  • Docs, tooling, or CI only
  • Other (describe above)

CI checklist

  • python tests/tools/audit_check.py passes (bundles the ruff/mypy/dead-key baseline-gated audits + ruff format --check)
  • python -m pytest tests/ passes
  • Touches parsing/engine logic? python tests/tools/crucible_check.py passes: no drift in either mode
  • Touches parsing/engine logic? python tests/tools/tree_sitter_accuracy_audit.py --all --ci passes
  • Changes the CLI's output JSON schema? No. It adds a nullable file_data column (SQLite) with an upgrade guard for existing databases; no JSON output changes.

Measurements

import_graph_accuracy.py, all 20 languages:

kotlin (square/kotlinpoet) before after
recall 95.2% 99.2%
missed imports 18 3
precision 100.0% 100.0%

No other language moved; the baseline is regenerated.

Three misses remain:

  • 2 point at Taggable.kt. I haven't looked into that shape; it isn't a property.
  • 1 is a genuinely ambiguous import (truth names several files).

Golden masters: no drift in either mode. The crucible's Kotlin samples don't import top-level properties.

keyword-rosetta: 51 languages, 0 regressions. X-Ray: 0 anomalies, checked locally this time before pushing.

Differential Scan target

The import-graph corpus: square/kotlinpoet.

Verification

$ pytest tests/security_auditing/test_kotlin_property_imports_3660.py     -- 22 passed
$ pytest tests/                                                           -- 11690+ passed, 0 failed
$ python tests/tools/audit_check.py                                       -- all clear
$ python tests/signal_contract_audit.py --ci                              -- no new findings (render regenerated)
$ python tests/tools/import_graph_accuracy.py --ci                        -- OK, 20 languages (kotlin 95.2 -> 99.2 recall)
$ python tests/tools/tree_sitter_accuracy_audit.py --ci --all             -- all OK
$ python tests/tools/crucible_check.py --mode both --update --yes         -- no drift
$ python tests/tools/rosetta_audit.py --corpus ../keyword-rosetta         -- 51 languages, 0 regressions
$ xray-inspector .                                                        -- 0 anomalies

The new test file covers:

  • 9 property shapes that should be captured, and 4 that shouldn't (private, a class member, a local, an indented object member);
  • linear-time payloads;
  • resolution with and without declared_names;
  • a persist and rehydrate round-trip, with the rehydrated files resolving the same edge.

🤖 Generated with Claude Code

https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr


Generated by Claude Code

…its file (#3660)

#3596 resolves `import a.b.name` to the file declaring `name`, but indexed only
functions and classes, so kotlinpoet's imports of extension properties
(`internal val KmConstructor.isPrimary`) resolved to nothing.

- kotlin `_declaration_capture` (a registered helper key): unindented top-level
  `val`/`var` names, any receiver (`KmType?.`, `<T> List<T>.`), annotations
  (incl. `@get:`) and modifiers first, never `private`. Bounded.
- galaxyscope runs it over the code stream into the file's `declared_names`;
  the resolver indexes them beside functions and classes.
- file_data.declared_names (JSON, NULL when none) + the rehydrator, so a delta
  scan resolves the same edges (the #3220 raw_imports precedent).

import_graph_accuracy (kotlin): recall 95.2% -> 99.2% (FN 18 -> 3), precision
100%. No other language moved; golden masters unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01GCpfMCUMpco98QGbsuv2sr
@github-actions

Copy link
Copy Markdown
Contributor

🐦‍⬛ Muninn Security Scan

✅ No security issues found.

🐦‍⬛ Powered by Muninn · Skald Lab

@squid-protocol
squid-protocol merged commit fdfd1ab into main Sep 26, 2026
36 checks passed
@squid-protocol
squid-protocol deleted the claude/kotlin-property-imports-3660 branch September 26, 2026 15:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Import graph: dart conditional imports, symlinked headers, kotlin extension properties, solidity basename guess

2 participants