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 inference path, patch it consistently with existing initializer handling, and run the focused and broader relevant test suites.
- Assistant
The repository is Rust-based and already contains Angular-specific fixtures, including one named
angular-inject-class-members, which is likely directly relevant. I’ll inspect that fixture, its snapshot/assertion wiring, and the Angular analyzer code that maps component fields to class types. - Assistant
The existing inject fixture verifies TypeScript-side member access through
inject(InnerService), not template-side access, so the call inference exists somewhere but is not being reused by Angular template binding. I’ll now inspect the focused Angular integration test and plugin/parser implementation to identify the exact branch discrepancy. - Assistant
Angular template extraction lives in
crates/extract/src/sfc_template. I’ll inspect its reference model and the TypeScript visitor portions that consume template references and infer receiver classes, especially around class property definitions. - Assistant
The TypeScript visitor already has
extract_angular_inject_targetand records aninstance_bindingfor class fields, while the template scanner emits both bare component references and dotted(receiver, member)references. The likely defect is ordering or a separate analysis bridge that only examines annotations/new. I’ll inspect the class visitor around these bindings and all sentinel consumers. - Assistant
Extraction does record
this.exampleService -> ExampleService, but external HTML is a separate module, so analysis must translate template receiver names using bindings from the importing component module. I’ll inspect that translation; the mismatch may simply be that it looks forexampleServicewhile extraction storesthis.exampleService. - Assistant
The defect is now isolated: ordinary TypeScript accesses use
binding_target_names, which already supports Angularinject(), but the external-template bridge usesclass_heritage.instance_bindings, populated by a separate helper. I’ll inspect and amend that helper to recognize only the genuine Angularinjectimport (including aliases, if its current inputs allow it), avoiding accidental inference from unrelated functions namedinject. - Assistant
extract_class_instance_bindingsis AST-only and cannot verify import provenance, so teaching it that anyinject()call is Angular would create false negatives in non-Angular code. A safer design is to pass an Angular-specific flag (already computed at every call site) and acceptinject()only for Angular-decorated classes; ideally also validate the import. Since helper calls occur during traversal after imports have been visited, I’ll assess whether changing it into an extractor method usingis_named_import_fromis practical, or whether passing the imported local name is cleaner. - Assistant
There are three helper call sites plus local/export duplication. The cleanest minimal change is to extend the helper with an optional verified Angular
injectlocal binding, obtained from the extractor’s import table. This supports aliased imports and rejects same-named non-Angular functions. I’ll inspect the import representation and existing provenance helper, then implement the parameter and update every call site. - Assistant
I’ll implement provenance-aware inference directly in
extract_class_instance_bindings: after annotation andnewhandling, recognize a call whose callee satisfies a callback supplied by the visitor, infer frominject<T>(...)first and then its identifier argument, matching existing behavior. Every caller will pass the existing@angular/corenamed-import check, preserving alias support and excluding unrelatedinjectfunctions. - Assistant
The first edit is structurally correct but formatting exposed two issues to clean up: format the closure call sites and make the existing provenance helper visible to its sibling
declarationsmodule. Then I’ll run extractor tests and the Angular integration test. - Assistant
The code compiles and existing focused tests pass, but that integration fixture only covers constructor DI. I need verify the exact reported case end-to-end without adding repository tests. I’ll create the reproduction under
/tmp, run the freshly built CLI against it, and also inspect extracted heritage via an existing debug path if needed. First I’ll build the CLI and execute its correct command syntax. - Assistant
The exact end-to-end reproduction now reports only the deliberately unused control member;
ExampleService.onValueChangeis correctly credited. To explicitly verify the original failure as requested, I’ll temporarily preserve the patch, build the unmodifiedHEAD, run the same/tmpfixture (where both methods should be reported), then restore and rebuild the fixed sources. No repository tests or fixtures will be modified. - Assistant
The attempted baseline comparison was invalid because Fallow reused the extraction cache created by the fixed binary—the unchanged output despite reverting the relevant helper confirms this. I’ll locate and remove the reproduction cache, rerun
HEADand fixed builds with cache clearing between them, and ensure the baseline actually demonstrates the false positive. - Assistant
The cache is
/tmp/fallow-angular-inject-repro/.fallow/cache.bin, and the CLI supports--no-cache. I’ll repeat the controlled comparison with caching disabled. - Assistant
The no-cache comparison successfully reproduced and resolved the defect: baseline reported
onValueChange, fixed did not, while the genuine unused control remained reported. I’ll now test edge cases without changing repository tests: an aliased Angularinjectimport should resolve, while an unrelated function namedinjectmust not create a service binding. Then I’ll run all extractor tests and the complete core integration suite. - Assistant
All 1,681 extractor tests and all 641 core integration tests pass. The manual edge checks also confirm aliased imports work and unrelated
injectfunctions remain excluded. I’ll review the final diff for API clarity and run formatting plus strict Clippy on the changed crate, then inspect repository status before submission.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.