service member referenced in an Angular external template is reported as unused when the…
- User
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:tsreadonly 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:json{ "name": "fallow-angular-template-repro", "version": "1.0.0", "private": true, "dependencies": { "@angular/core": "^20.0.0" } } -
Create
.fallowrc.json:json
-
- Assistant
I'll investigate how the Angular plugin resolves component properties to service types for template references, focusing on the untyped
inject()case. - Assistant
Implementing the fix:
extract_class_instance_bindingshandles typedinject()andnew, but not untypedinject()— that's what Angular external templates use. - Assistant
Fixed. The root cause was that
extract_class_instance_bindings(used to resolveprop.method()in Angular external templates) handled constructor injection, typed properties, getters, andnewinitializers — but not untypedinject()calls.visit_property_definitionalready mappedthis.exampleService.foofor untypedinject()viabinding_target_names, which is whythis.inner.aaaworked in TS but template references did not.Fix
Added
extract_inject_call_target()inhelpers.rsand wired it intoextract_class_instance_bindingsfor property definitions likereadonly exampleService = inject(ExampleService). Also refactoredextract_angular_inject_targetinvisit_impl.rsto use the shared helper.Tests
- Unit tests: untyped
inject(ExampleService)and genericinject<ExampleService>()both record instance bindings - Integration fixture
tests/fixtures/angular-inject-template-members/covering the exact repro from the bug report
All new and existing tests pass.
- Unit tests: untyped
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.