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 angular plugin active, fallow dead-code reports a service method as an
unused class member when its only reference is in an Angular HTML template
(prop.method()), and the component property prop is initialized with the modern
inject() 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:
Because untyped inject() is the idiomatic Angular style, this misfires on a very common
real-world pattern.
Reproduction
Minimal standalone repro. @angular/core only needs to be listed in package.json so the
angular plugin auto-activates — running npm install is optional (without it, fallow prints
a "node_modules directory not found" warning but the finding still reproduces).
import { ExampleComponent } from './example.component';
console.log(ExampleComponent);
Assistant
Now implement the fix.
Assistant
Now let's build.
Assistant
Now create the repro project and test.
Assistant
Reproduced without the fix. Now rebuild with fix and verify.
Assistant
Now update the helper signature and gating.
Assistant
Now add the visitor helper providing inject local names and update call sites.
Assistant
All checks complete. Let me review the checklist:
Reproduced the reported error: Yes. I built the CLI from the pre-fix tree and ran the exact repro from the issue (/tmp/repro); ExampleService.onValueChange was reported as an unused class member (with a fresh cache — the first run reused a stale .fallow cache, which I cleared).
Confirmed my fix resolves the error: Yes. After the change, the repro reports only the genuinely-unused control method (reallyUnused), and onValueChange is credited. Verified both cold and warm cache runs (I also bumped CACHE_VERSION 113 → 114, matching repo convention, so warm caches from older versions don't retain pre-fix extraction data).
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
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);
}
── Unused Code ─────────────────────────────────────
● Unused class members (1)
src/example.service.ts
:6 ExampleService.onValueChange
Class methods or properties never referenced outside their class
✗ 1 class member
onValueChange is reported as unused even though it is referenced in
example.component.html.
Controls that isolate the root cause
Keeping the template (input)="exampleService.onValueChange(...)" unchanged and only varying
how exampleService is declared on the component:
Control A — constructor injection: replace the inject() field with
constructor(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 — new initializer: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, and new expressions, but not an untyped inject() initializer, so
the template reference exampleService.onValueChange is never credited to ExampleService.
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 typed inject(), constructor injection, and new initializers. No
unused-class-member finding should be reported in the repro above.
Fallow version
fallow 2.83.0
Operating system
macOS
Configuration
default
Interface
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 using git reset --hard command.
Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later.
Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands.
However you don't need to use git add or git commit before submitting your changes. In fact,
submit only submits currently unstaged changes because it uses git diff to 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-$
Edge cases: extract_class_instance_bindings now resolves inject() field initializers, handling: explicit type args (inject<Service>(TOKEN)), extra options args (inject(Service, { optional: true })), as / ! / parenthesized wrappers, aliased imports (inject as ngInject), builtin-constructor filtering, class type-param constraint resolution, and the existing precedence order (type annotation → new → inject). Private fields remain excluded, matching the other patterns. The inject callee is gated on a named import from @angular/core (same convention as the existing extract_angular_inject_target), so a same-named inject from another module still creates no credit — verified with a ./container control that keeps reporting the member.
Ran existing tests: Yes — cargo test --workspace passes except fix_batch_aborts_when_a_target_directory_is_read_only, which also fails on the unmodified baseline (the sandbox runs as root, so read-only dirs are still writable) — unrelated to my change. cargo fmt --all and cargo clippy --workspace --all-targets are clean. I added no tests and modified none; I added a CHANGELOG entry per repo convention.