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:
ts
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).
Now let's find where property -> service type binding actually happens (angular plugin's handling of component properties, constructor params, inject calls).
Assistant
Found it. Let's look at extract_class_instance_bindings in helpers.rs.
Assistant
Now update extract_class_instance_bindings in helpers.rs:
Assistant
Now update all call sites to pass the closure.
Assistant
Now let's build to check for compile errors.
Assistant
Builds fine. Now let's check other test call sites, e.g., unused_members.rs tests that call extract_class_instance_bindings directly.
Assistant
Now let's build whole workspace and set up the reproduction test.
Assistant
Whole workspace builds. Now let's create the reproduction fixture and run the CLI.
Assistant
The fix works. Let's verify by reverting the fix temporarily to confirm it reproduces the bug (sanity check), then restore.
Assistant
Good, changes are present. Let's redo the stash test more carefully to confirm the bug actually reproduces without the fix.
Assistant
There's a cache. Let's clear it and retest without fix.
Assistant
Confirmed the bug reproduces without the fix. Now let's restore the fix and rebuild.
Assistant
Fix confirmed. Now let's also test the three control cases still work (constructor injection, typed inject, new expression) to make sure nothing broke.
Assistant
All four scenarios pass now. Let's also test an edge case: inject() where the argument is NOT identifier (e.g., some other injection token) to make sure it doesn't break, and also test that non-angular inject local function (not imported from @angular/core) doesn't get falsely matched.
Assistant
This correctly avoids false negatives for a locally-defined inject shadow (not from @angular/core), meaning the import check works correctly. Now let's run the existing test suite to make sure nothing is broken.
Assistant
All pass. Now let's run fallow-core tests, especially angular related integration tests.
Assistant
All 641 tests pass. Now let's run the full workspace test suite to be thorough.
Assistant
Confirmed this failure is pre-existing (likely because tests run as root, so read-only permission doesn't block writes) and unrelated to our change. Let's continue running the rest of the workspace tests, skipping this pre-existing failing test.
Assistant
All the remaining tests pass. Let's confirm the total summary explicitly by checking exit code and any failures count throughout.
Assistant
Good, formatting is clean now. Let's rebuild and re-run tests one more time to be safe.
Assistant
All good. Let's view the final diff for review.
Assistant
This looks clean and minimal. Now let's go through the checklist.
Assistant
No clippy warnings. Everything checks out. Let's do a final review of the git status before submitting.
Assistant
Checklist review
If an error was reported in the issue description, I have successfully reproduced it.
Yes — I built a minimal repro exactly matching the issue (Angular component with readonly exampleService = inject(ExampleService); and a template calling ), ran , and confirmed was reported as an unused class member, matching the issue exactly.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
import { ExampleComponent } from './example.component';
console.log(ExampleComponent);
Create src/example.service.ts:
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:
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
toml
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-$
exampleService.onValueChange(...)
fallow dead-code
ExampleService.onValueChange
If an error was reported in the issue description, I have confirmed that my fix resolves the error.
Yes — after applying the fix, the same repro now reports ✓ No issues found. I also verified by git stash/git stash pop that the bug reproduces on the unmodified code and disappears with my change (after clearing the .fallow cache directory that had been misleading an earlier check).
I have thought about edge cases and made sure my fix handles them as well.
Yes:
Verified the three "control" patterns from the issue (constructor injection, typed inject(), new expression) still resolve correctly (no regression).
Verified a negative case: a locally-declared inject<T>() helper function (not imported from @angular/core) is not mistakenly treated as Angular's DI inject, since the fix uses is_named_import_from to check the import source, not just the identifier name.
The root cause fix (extract_class_instance_bindings) is applied uniformly across all 3 call sites (named class declarations, default-exported classes, and class expressions), so the fix generalizes beyond just components — any class instance binding resolution benefits from recognizing untyped inject() initializers.
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
Yes — ran cargo test -p fallow-extract (1681 passed), cargo test -p fallow-core (641 passed, including all Angular-specific integration tests), and cargo test --workspace (all passed except one pre-existing, unrelated failure fix_batch_aborts_when_a_target_directory_is_read_only, which I confirmed also fails identically on the unmodified codebase — likely an environment artifact of running as root where read-only directories don't block writes). Also ran cargo fmt and cargo clippy with no issues.