ISSUE DESCRIPTION service member referenced in an Angular external template is reported…
- User
ISSUE DESCRIPTION
service member referenced in an Angular external template is reported as unused when the component property is initialized with
inject()(no explicit type annotation)What happened?
With the
angularplugin active,fallow dead-codereports a service method as an unused class member when its only reference is in an Angular HTML template (prop.method()), and the component propertypropis initialized with the moderninject()pattern without an explicit type annotation:readonly exampleService = inject(ExampleService);Fallow already credits template references through component properties for the other three DI/instance patterns — it is specifically the untyped
inject()initializer that is missed. The following all resolve correctly (no false positive); only the last one fails:Component property pattern Template prop.method()resolved?constructor(public svc: ExampleService) {}✅ yes svc: ExampleService = inject(ExampleService);(typed)✅ yes svc = new ExampleService();✅ yes svc = inject(ExampleService);(untyped)❌ no — false positive Because untyped
inject()is the idiomatic Angular style, this misfires on a very common real-world pattern.Reproduction
Minimal standalone repro.
@angular/coreonly needs to be listed inpackage.jsonso theangularplugin auto-activates — runningnpm installis optional (without it, fallow prints a "node_modules directory not found" warning but the finding still reproduces).-
Create
package.json:{ "name": "fallow-angular-template-repro", "version": "1.0.0", "private": true, "dependencies": { "@angular/core": "^20.0.0" } } -
Create
.fallowrc.json:{ "entry": ["src/main.ts"] } -
Create
src/main.ts:import { ExampleComponent } from './example.component'; console.log(ExampleComponent);
-
- Assistant
I’ll first inspect the repository structure, package scripts, and Angular plugin implementation/tests. Then I’ll reproduce the reported case using the project’s normal test workflow, trace the component-property type resolution, implement the narrow fix, and run focused plus broader tests.
- Assistant
This is a Rust workspace. I’ll locate Angular-specific extraction and fixture coverage, especially code that maps template property chains to class types and recognizes
newexpressions or type annotations. - Assistant
rgis unavailable in this environment, so I’ll use recursivegrepandfindto perform the same search. - Assistant
The key analysis is in
unused_members.rs, with an existing integration fixture for Angular template inheritance/DI and a separate test forinject()fields used from TypeScript. I’ll inspect the chain-crediting algorithm and extracted model fields to determine whether the missing information should be captured during AST extraction or inferred during analysis. - Assistant
The template algorithm relies on
class_heritage.instance_bindings: the bug likely means extraction records declared types andnew, but not call-based inference. I’ll find that model’s producer and inspect the actual fixture files before changing anything. - Assistant
I found the extractor helper and its unit tests. I’ll read its full matching logic and nearby AST helper conventions, along with the template fixture’s current DI declaration, to identify the minimal generalization and expected alias behavior.
- Assistant
The helper currently infers only
new Identifier(). The reported form can be handled by inferring the first argument of aninject(...)call. Before editing, I’ll inspect how ordinary TypeScript accesses already inferinject()and the Oxc AST version/types, so the implementation is consistent and handles wrappers such as optional chaining or generic arguments appropriately without over-crediting arbitrary factories. - Assistant
There is already a deliberately import-aware recognizer that only accepts Angular’s real
injectimport and rejects same-named local utilities. Reusing that is important to avoid introducing false mappings. I’ll inspect that recognizer and every call site ofextract_class_instance_bindings; because the helper is currently stateless, the clean fix may be to pass an optional callback or augment bindings in visitor contexts where imports are known. - Assistant
The existing recognizer also supports
inject<Type>(token)and import aliases throughis_named_import_from, so duplicating a simplistic name check would regress correctness. I’ll inspect module traversal/import recording and the secondary declaration extractor to decide whether to centralize an import-aware method onModuleInfoExtractorand ensure all exported-class paths use it. - Assistant
A safe design is an import-aware extractor method that starts with existing annotation/
newbindings, then adds only public/protected untyped properties whose initializer is recognized by the existing Angular-import-awareinjectlogic. This preserves explicit annotations as authoritative, supports aliases and genericinject<T>(), and continues rejecting unrelatedinjectfunctions.Before editing, I’ll reproduce the issue in a temporary fixture outside the repository (so no tests are modified) using the workspace CLI.
- Assistant
The first build invocation only needed an explicit binary selection. I’ll rerun with
--bin fallowand capture the baseline JSON finding. - Assistant
The absolute config path did not change the CLI project root, so that run analyzed the repository rather than the temporary project. The binary is now built; I’ll invoke it from the fixture directory to obtain a valid baseline.
- Assistant
The expected nonzero exit confirms findings were emitted; my summary script assumed the wrong JSON field name. I’ll inspect only the compact unused-member objects, then return to the repository for implementation.
- Assistant
The baseline reproduces exactly: both the template-used method and the genuine control are reported. I’ll now add the import-aware class-binding method and switch all three visitor extraction paths (local/named export/default export) plus the declaration helper to use it.
- Assistant
The AST types are already wildcard-imported in
visit_impl.rs. I’ll place the method next toextract_angular_inject_target, skip fields that already have annotations, preserve the existing private-field exclusion, and avoid duplicate(property, type)entries. - Assistant
The implementation is in place and all class extraction paths now share it. I’ll first run the extractor unit suite and the focused Angular template integration module; compilation will also reveal any borrow/privacy issues.
- Assistant
Focused tests pass. Next I’ll rebuild the CLI with the fix and rerun the exact temporary repro, verifying that only
onValueChangedisappears whilegenuinelyUnusedremains. - Assistant
The end-to-end repro still fails despite unit/integration compilation, so the new binding is not reaching the exported component heritage. I’ll inspect
is_named_import_fromand traversal order, then instrument via existing extraction APIs or a temporary debug print (removed afterward) to determine whether recognition or heritage merging drops the binding. - Assistant
I’ll inspect
visit_programand import insertion completion. A likely cause is a pre-scan that walks declarations before imports are populated, or duplicate heritage records where a later empty record shadows the enriched one during analysis. - Assistant
Imports are populated in source order, so the repro’s imports should be available. I’ll add a temporary diagnostic inside the new method, run only extraction/CLI once, and immediately remove it; this will show whether the method recognizes the target and how often each class path is processed.
- Assistant
The absence of diagnostics is consistent with Fallow reusing its extraction cache for unchanged fixture files, not necessarily with the method failing. I restored the diagnostic edit, which also restored the source file, so I’ll reapply the intended patch and rerun with cache disabled (or remove the fixture cache) to test fresh extraction.
- Assistant
The CLI supports
--no-cache, and the temporary fixture indeed contains an oldcache.bin. I’ll rebuild and rerun fresh extraction now. - Assistant
Fresh extraction confirms the fix: the template-used method is no longer reported, while the genuine unused control remains. I’ll exercise two edge cases in temporary fixtures without altering repository tests: an aliased Angular import and generic
inject<ExampleService>(TOKEN). Then I’ll run the broader relevant integration tests and lint. - Assistant
The alias/generic edge case also resolves correctly, and all Angular-filtered core integration tests pass. I’ll now run Clippy with warnings denied for the two affected crates, then inspect the final diff and repository status for accidental changes.
- Assistant
Clippy passes with no warnings, the diff is limited to the extractor, and formatting checks are clean. I’ll make one final temporary control check that a public property initialized by a non-Angular same-named
injectis not credited, then run the complete core integration-test binary to guard against broader member-analysis regressions. - Assistant
All 641 core integration tests pass, and the non-Angular control remains intentionally unresolved, confirming the change does not treat arbitrary same-named factories as Angular DI.
Checklist:
- [x] Successfully reproduced the reported error. In a temporary standalone Angular fixture, fresh analysis initially reported both
ExampleService.onValueChange(false positive) and the deliberately unused control. - [x] Confirmed the fix resolves the error. Running the rebuilt CLI with
--no-cacheremovedonValueChangewhile retaininggenuinelyUnused. - [x] Considered edge cases. The implementation preserves explicit annotations, excludes private template-inaccessible fields, reuses import-aware Angular recognition, supports aliased imports and generic
inject<T>(), and rejects a public property using a non-Angularinject. - [x] Ran affected existing tests. The 302 extractor visitor tests, focused/all Angular integration tests, the complete 641-test core integration suite, and Clippy with warnings denied all pass.
cargo fmt, , and final diff inspection are clean.
- [x] Successfully reproduced the reported error. In a temporary standalone Angular fixture, fresh analysis initially reported both
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.