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 and locate the Angular template/member-resolution implementation and its tests. Then I’ll reproduce the failing pattern, patch the general property-type inference path, and run focused plus broader tests.
- Assistant
This is a Rust workspace, and the initial path-limited search missed the implementation because it lives under crate-specific paths. I’ll map the relevant crates and search the entire tracked tree for Angular plugin and template symbol-resolution code.
- Assistant
The key logic is in
unused_members.rs: Angular templates produce sentinel member accesses, then a second pass mapscomponentProperty.memberchains to the property’s class type. I’ll inspect that mapping and the extractor’s representation of class property annotations/initializers to identify the narrow missing call-expression case. - Assistant
The analysis consumes
class_heritage.instance_bindings, so the proper fix belongs in extraction where those bindings are populated. The extractor already infersnew ExampleService()at the likely location around line 1877; I’ll inspect that function, its AST helpers, and nearby extraction tests before editing. - Assistant
Although
visit_property_definitionalready recordsinject()in a general binding map, Angular’s template bridge specifically reads per-classinstance_bindings, which are independently extracted byextract_class_instance_bindings. That explains why the existing code does not help this path. I’ll inspect and extend that helper, reusing the same strict Angular inject recognition semantics if possible (including aliases and avoiding arbitrary user-definedinject). - Assistant
A subtle architecture constraint appears: the helper receives only a
Class, not module imports, so it cannot validate whetherinjectwas imported from@angular/core. The existing module-aware recognizer can. I’ll inspect its exact implementation and class-declaration call flow to decide whether to pass validated Angular inject local names into the helper or infer bindings later without introducing false positives. - Assistant
The robust design is to pre-scan module imports at
visit_program, collecting local names bound to Angular’s namedinjectexport (so aliases work and source order does not matter), then pass that set into class binding extraction. This keeps genericinject(...)functions from being mistaken for Angular DI. I’ll inspect the extractor struct construction and Oxc import AST handling, then implement the smallest signature change across the three class extraction call sites. - Assistant
I’ll add an
angular_inject_bindingsset to extractor state, populate it in a pre-pass over top-levelImportDeclarations, and update the helper to infer a property type only when the call’s identifier is in that validated set. The helper will continue prioritizing explicit annotations, preserve private-member exclusion, support generic type arguments (inject<TokenType>(TOKEN)), and otherwise use the first identifier argument (inject(Service)). - Assistant
I’m now applying the implementation: validated import pre-scan, a module-aware wrapper around the existing helper, call-site updates, and call-expression inference in the helper. After compiling, I’ll use existing test infrastructure (without adding repository tests, per instruction) and a temporary fixture/script for end-to-end reproduction.
- Assistant
The patch is formatted. Before end-to-end testing, I’ll compile and run the extractor’s existing test suite; this will catch AST enum/API mismatches and regressions in class binding extraction.
- Assistant
Compilation found only a missing
FxHashSetimport in the helper module. I’ll add it and rerun the focused suite. - Assistant
All 1,681 extractor tests pass. Next I’ll reproduce the exact report end-to-end in
/tmpusing the issue’s files. I’ll first run the repository CLI against the untypedinject()fixture and verify the false positive is absent. Since the patch is already applied, I’ll also directly inspect extracted heritage through the CLI behavior and later compare controls/edge cases such as aliased Angular imports and a non-Angular function namedinject. - Assistant
The fixture is ready; the first invocation only failed because the CLI crate has multiple binaries. I’ll rerun explicitly with
--bin fallow, checking its accepted working-directory syntax if needed. - Assistant
The CLI uses the process working directory rather than a
--cwdflag. I’ll execute from the temporary project while pointing Cargo at this repository’s manifest. - Assistant
Running outside the repository prevents Rustup from discovering
rust-toolchain.toml. I’ll set the repository toolchain explicitly and rerun. - Assistant
Now I’ll run the exact dead-code command with that toolchain from the fixture directory.
- Assistant
The patched CLI resolves the exact reproduction (
✓ No issues found). To satisfy the requirement to confirm the original error itself, I’ll temporarily save and reverse only my source diff, run the same fixture to observe the false positive on baseline, then immediately reapply the saved patch. This does not alter tests or leave temporary repository changes. - Assistant
The temporary baseline run incorrectly reused Fallow’s analysis cache from the fixed run, so it did not exercise baseline extraction. I’ll repeat the controlled reversal after deleting the fixture cache (and identify all hidden cache paths), then restore the patch and clear cache again before final verification.
- Assistant
I found
.fallow/cache.bin. I’ll now rerun baseline without that cache and restore the patch regardless of the CLI’s nonzero finding exit. - Assistant
Baseline now reproduces exactly: one unused
ExampleService.onValueChange, exit 1. The patch has been restored. I’ll rerun cache-free to confirm the fix, then exercise alias/generic-token support and verify a local non-Angularinjectfunction is not over-credited. - Assistant
The cache-free fixed run passes. I’ll now swap only the temporary component declaration for two edge cases, clearing cache each time: aliased
inject<ExampleService>(TOKEN)should pass; a same-named local helper should still report the service method unused. Then I’ll restore the exact fixture source. - Assistant
Edge behavior is correct: Angular aliases and generic injection tokens resolve, while an unrelated local
injectdoes not. I’ll now run the core analyzer’s unused-member tests (the downstream consumer ofinstance_bindings) and workspace lint/format checks relevant to the changed crate. I’ll also review the final diff for accidental changes. - Assistant
Review shows one consistency improvement: explicit class annotations resolve generic type parameters through their constraints, but the new
inject<T>()inference currently would retain rawT. I’ll route the inferred type through the sameresolveclosure so constrained generics map correctly and unconstrained generics remain safely uncredited, then rerun focused checks. - Assistant
All focused tests and Clippy pass after the generic-resolution refinement. I’ll perform one final cache-free end-to-end run of the exact restored issue fixture, then inspect final status/diff summary before submission.
- Assistant
Implementation is complete and verified. The extractor now pre-validates named/aliased Angular
injectimports, infers class instance bindings from eitherinject(Service)orinject<Type>(token), preserves generic-constraint resolution, and avoids treating unrelated localinjectfunctions as Angular DI.Checklist:
- Successfully reproduced the reported error. With the patch temporarily reversed and
.fallow/cache.binremoved, the exact fixture reportedExampleService.onValueChangeas one unused class member and exited 1. - Confirmed the fix resolves the error. With the patch restored and cache removed, the exact fixture reports
✓ No issues foundand exits 0. - Considered edge cases. Verified aliased Angular imports and generic-token injection resolve correctly; verified a non-Angular local function named does not receive false credit. Private properties remain excluded, explicit annotations retain precedence, and constrained generic types use existing resolution.
- Successfully reproduced the reported error. With the patch temporarily reversed and
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.