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); -
Create
src/example.service.ts:import { Injectable } from '@angular/core'; @Injectable({ providedIn: 'root' }) export class ExampleService { // Only referenced from example.component.html via an event binding. onValueChange(value: string): void { console.log(value); } } -
Create
src/example.component.ts:import { Component, inject } from '@angular/core'; import { ExampleService } from './example.service'; @Component({ selector: 'app-example', templateUrl: './example.component.html', }) export class ExampleComponent { // Exposed to the template so the binding can call exampleService.onValueChange(...) readonly exampleService = inject(ExampleService); } -
Create
src/example.component.html:<input (input)="exampleService.onValueChange($event.target.value)" /> -
Run:
npx fallow dead-code --config .fallowrc.json
Actual output
── Unused Code ───────────────────────────────────── ● Unused class members (1) src/example.service.ts :6 ExampleService.onValueChange Class methods or properties never referenced outside their class ✗ 1 class memberonValueChangeis reported as unused even though it is referenced inexample.component.html.Controls that isolate the root cause
Keeping the template
(input)="exampleService.onValueChange(...)"unchanged and only varying howexampleServiceis declared on the component:- Control A — constructor injection: replace the
inject()field withconstructor(public exampleService: ExampleService) {}. Result:✓ No issues found. - Control B —
inject()with an explicit type annotation:readonly exampleService: ExampleService = inject(ExampleService);. Result:✓ No issues found. - Control C —
newinitializer:readonly exampleService = new ExampleService();. Result:✓ No issues found.
Only the untyped
inject()initializer (the repro above) produces the false positive. This points at the component-property → service-type binding step: it resolves type annotations, constructor parameters, andnewexpressions, but not an untypedinject()initializer, so the template referenceexampleService.onValueChangeis never credited toExampleService.Expected behavior
A service member referenced from an Angular template via a component property should be credited as used when that property is initialized with
inject()— the same way it already is for typedinject(), constructor injection, andnewinitializers. Nounused-class-memberfinding should be reported in the repro above.Fallow version
fallow 2.83.0
Operating system
macOS
Configuration
defaultInterface
No new interfaces are introduced.
ADDITIONAL ADVICE
Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use
git checkout <file>to restore the file to its original state. You can also reset all changes in the repository usinggit reset --hardcommand. Additionally, you can usegit stashandgit stash popto temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you callsubmit) usinggit statusorgit diffcommands. However you don't need to usegit addorgit commitbefore submitting your changes. In fact,submitonly submits currently unstaged changes because it usesgit diffto get the changes that need to be submitted.CHECKLIST
Before submitting your solution, please go over the following checklist and make sure you've done everything:
- If an error was reported in the issue description, I have successfully reproduced it.
- If an error was reported in the issue description, I have confirmed that my fix resolves the error.
- I have thought about edge cases and made sure my fix handles them as well.
- I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.
Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!
(Current directory: /fallow, current file: none) bash-$
-
Assistant
Now let me add the new method after
extract_angular_inject_target:Assistant
Now let me create the repro to verify. First, reproduce with the original code (stash the fix):
Assistant
The fix works (cache was stale). Let me check whether the extraction cache has a version that should be bumped:
Assistant
Edge cases verified. Now run the existing test suites:
Assistant
All tests pass. Final check of repo state and one last end-to-end verification:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
Identical first prompt
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
claude-sonnet-5Compare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.6-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →
Qwen/Qwen3.5-35B-A3BCompare side by side →