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: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 first inspect the repository structure, package scripts, and Angular/template analysis code. Then I’ll reproduce the reported behavior with a temporary fixture or existing test harness, trace how property types are inferred, implement the narrow inference fix, and run the relevant and broader tests.
- Assistant
The project is a Rust workspace. I’ll locate Angular plugin implementation and tests, especially code that maps template property chains to class symbols and handles
newexpressions or type annotations. - Assistant
ripgrepis unavailable in the environment, so I’ll use recursivegrepand file discovery instead. - Assistant
There are two relevant paths: general TypeScript member-chain inference already has an
inject()regression test, while Angular external-template chain inference is inunused_members.rs. I’ll inspect that logic and its fixture representations to identify why the existing inject inference is not reused. - Assistant
The template propagation intentionally relies on
class_heritage.instance_bindings, so the defect is likely extraction: that map includes annotated fields andnewinitializers but not call initializers. I’ll trace whereinstance_bindingsis populated and compare it with the separate sentinel-basedinject()handling used for ordinary TS accesses. - Assistant
The extractor already validates that the callee is specifically Angular’s imported
inject, which is important to avoid treating arbitrary DI helpers as Angular types. I’ll inspect the helper and call-site ordering so the fix can reuse that semantic check rather than matching the textinjectgenerically. - Assistant
extract_class_instance_bindingsis a context-free AST helper, whereas recognizing an aliased Angular import requires visitor state. Simply addingCallExpressionthere would incorrectly accept non-Angularinject. I’ll inspect how exported/local class heritage is assembled; the likely robust approach is to augment its bindings in the stateful declaration visitors using the sameextract_angular_inject_targetmethod. - Assistant
Before editing, I’ll reproduce against a temporary project outside the repository. This avoids modifying tests while confirming the exact end-to-end failure. I’ll build/run the workspace CLI with the minimal files from the report.
- Assistant
The fixture is ready; Cargo only needs the explicit binary name. I’ll rerun using
--bin fallowand verify CLI argument placement from its help if needed. - Assistant
The global project-directory option is
--root, not--cwd. I’ll run the reproduction with that option. - Assistant
The failure reproduces exactly: both the template-used method and the control are reported. I’ll add a visitor-aware instance-binding extractor that starts with existing annotation/
newinference, then adds public/protected untyped property bindings only when the initializer is a call resolved to Angular core’s namedinjectimport. I’ll route all class-heritage construction paths through it. - Assistant
I’ll implement the method and update the three call sites (named exported declarations, local classes later exported, and default-exported classes). Explicit annotations remain authoritative, private properties remain excluded, and generic
inject<Type>(token)continues to work through the existing target extractor. - Assistant
The edit is structurally complete; the check only reports formatting differences. I’ll apply workspace formatting, compile and run the extractor tests (which cover Angular import validation), then rerun the end-to-end reproduction.
- Assistant
The extractor suite passes, but the CLI still shows the old result. Since this project caches extraction results and the fixture source did not change between binary runs, I need to distinguish stale cache from logic failure. I’ll rerun with the global no-cache option (checking exact spelling), then inspect extraction directly only if it remains unresolved.
- Assistant
With cache disabled, the false positive is fixed and the genuinely unused control remains, confirming correct behavior. Because this changes serialized extraction output for unchanged source, I’ll inspect cache versioning to ensure users upgrading do not retain stale module records—as demonstrated by the first rerun.
- Assistant
The stale-cache run confirms this is an extraction-semantics change, and the cache source explicitly requires a version bump for that case. I’ll increment it, then exercise key edge cases in temporary fixtures: aliased Angular
inject, genericinject<Service>(token), and a same-named non-Angular helper that must not receive credit. - Assistant
The edge-case results are correct: aliased and generic Angular calls leave only
genuinelyUnused, while the non-Angular helper leavesonValueChangereported. I’ll update the cache-version rationale, then run the relevant core integration tests, extraction cache tests, formatting, and Clippy on the changed crates. - Assistant
All targeted tests and strict Clippy pass. As a final cache verification, I’ll run the original reproduction without
--no-cache; the v114 bump should invalidate the previously persisted v113 result automatically. Then I’ll review the complete diff and repository status for unintended changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.