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
This is a Rust project. Let's look at the angular.rs plugin and the resolution logic for component property → service type.
Assistant
Now let's add handling for inject(Service) call. Let's check extract_type_reference_name helper for type args.
Assistant
Now insert the inject-call handling after the new-expression check.
Assistant
CallExpression isn't imported directly by name. Let's check the use statement list.
Assistant
I'll change the function signature to use oxc_ast::ast::CallExpression fully qualified, matching the pattern already used elsewhere in the file (line 271).
Assistant
Builds fine. Now let's build the reproduction fixture and run analysis via cargo test.
Assistant
The fix works. Now let's run the existing test suite related to this.
Assistant
All Angular-related tests pass. Now let's run the full test suite for the affected crates to be safe.
Assistant
All tests pass. Now let's run the full core test suite to be thorough.
Assistant
All 641 tests pass. Let's also add a fixture test-like verification for edge cases: generic type param inject, and check is_builtin_constructor guard works, and check that inject with no arguments doesn't crash.
Assistant
That's expected (unreachable file, unrelated to our fix), no crash. Let's remove the temp file and confirm original repro still clean.
Assistant
Clean. Now let's check git diff to review the final change.
Assistant
This is a minimal, targeted change. Let's clean up the temp repro directory.
Assistant
Confirmed: with my change, all 2328 tests pass too. The earlier failure was a flaky test unrelated to this change (likely a parallel-test filesystem/env race), not caused by my fix. Let's run the full workspace test suite once more to double check.
Assistant
Confirmed - this fails because we're running as root (read-only permission checks don't apply to root user), a pre-existing environment limitation unrelated to my change. Let's verify by stashing my change and running the same test.
Assistant
Confirmed pre-existing failure unrelated to my change (fails identically without my change too, due to running as root). This is an environment limitation, not something I broke. Now let's run all remaining tests excluding this known-flaky one to make sure everything else passes.
Assistant
All tests pass except the one pre-existing environment-specific failure (root permissions), which is unrelated to my change. The fix is complete and verified.
Assistant
Checklist review
[x] If an error was reported in the issue description, I have successfully reproduced it.
I built the exact repro from the issue (package.json, , , , with untyped , and ), built the CLI, and confirmed it reported as unused before my change.
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-$
.fallowrc.json
main.ts
example.service.ts
example.component.ts
readonly exampleService = inject(ExampleService);
example.component.html
ExampleService.onValueChange
[x] If an error was reported in the issue description, I have confirmed that my fix resolves the error.
After adding inject()-call recognition to extract_class_instance_bindings in crates/extract/src/visitor/helpers.rs, I reran fallow dead-code against the same repro and got ✓ No issues found.
[x] I have thought about edge cases and made sure my fix handles them as well.
Typed inject<Service>() type-argument form is still handled (checked first, matching the existing viewChild/contentChild pattern).
Untyped inject(Service) identifier-argument form is now handled (the actual bug).
Builtin constructors (e.g. inject(String)) are excluded via the existing is_builtin_constructor guard, avoiding false credit to non-class targets.
inject() with no arguments returns None safely without panicking (verified with a manual test).
The pre-existing new Expr() property-initializer branch was preserved and given an explicit continue for clarity, without changing its behavior.
I verified genuinely-unused members are still reported (existing tests like InnerService.ccc, unusedServiceMethod, unusedBaseMethod still assert correctly).
[x] I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass.
Ran cargo test -p fallow-extract, cargo test -p fallow-core, cargo test -p fallow-cli --bin fallow, and cargo test --workspace. All passed except one pre-existing, environment-specific failure (fix_batch_aborts_when_a_target_directory_is_read_only) that fails identically with and without my change because the test environment runs as root (permission-based read-only checks don't apply to root), confirming it's unrelated to this fix.
The change is minimal and localized to crates/extract/src/visitor/helpers.rs, adding recognition of the inject(ServiceType) call pattern (both typed and untyped) when extracting class instance bindings, which is the mechanism used to credit template references like exampleService.onValueChange() back to ExampleService.