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
Let me start by exploring the repository structure to understand what we're working with.
Assistant
Let me look at where Angular template references are handled and find the relevant code:
Assistant
Let me search for "template" usage and Angular template handling in unused_members.rs:
Assistant
Now let me search for the
instance_bindingsdata structure:Assistant
Let me examine the helpers file to see how
extract_class_instance_bindingsworks:Assistant
Let me look at the
extract_class_instance_bindingsfunction:Assistant
Now I have a clear understanding of the issue. Let me look at the test file for
extract_class_instance_bindings:Assistant
Let me look at the full
extract_class_instance_bindingsfunction with line numbers:Assistant
Let me search for
injecthandling in the codebase:Assistant
Let me look at the existing
extract_angular_inject_targetfunction:Assistant
Now let me see how this
extract_angular_inject_targetis used:Assistant
Let me search for the existing test that confirms the typed inject case works:
Assistant
Let me look at the integration test for angular template members:
Assistant
Now let me reproduce the issue:
Assistant
Let me look at the
is_named_import_frommethod to understand it:Assistant
Let me look at the visitor/mod.rs:
Assistant
Let me look at how
extract_class_instance_bindingsis called in the code:Assistant
Let me look at ImportInfo:
Assistant
Let me search for how
instance_bindingsis used:Assistant
Let me also look at how angular tpl chain accesses work:
Assistant
Let me check the existing imports in helpers.rs:
Assistant
Let me look at the AST types involved:
Assistant
Now let me look at the existing
extract_angular_inject_targetmore carefully to ensure I follow the same logic:Assistant
Let me look at the existing tests for
extract_class_instance_bindings:Assistant
Now let me look at the
parse_tsfunction used in tests to see if it gives access to imports:Assistant
Let me look at a relevant existing test that tests
instance_bindings:Assistant
Now I have all the context I need. Let me design and implement the fix.
First, let me look at all callers of
extract_class_instance_bindingsto make sure I update them properly:Assistant
Now let me implement the fix. First, let me look at how
helpers.rsis organized:Assistant
Let me also look at the
type_name_rootfunction:Assistant
Let me look at all uses of
type_name_root:Assistant
Let me look for any existing helpers in helpers.rs that could extract type names:
Assistant
Now I have a clear plan. Let me implement the fix. I'll first modify
helpers.rsto:- Add
type_name_rootas a helper function - Add
extract_angular_inject_targethelper that takes imports as parameter - Modify
extract_class_instance_bindingsto accept imports and use the new helper
- Add
Assistant
Good. Now let me modify
helpers.rs. First, I'll add theImportedNameimport:Assistant
Let me try a different approach using
replace:Assistant
Now let me update the
extract_class_instance_bindingsfunction and add helper functions. First let me re-read the function:Assistant
Now let me modify the function and add helpers:
Assistant
Now I need to update the visitor method that uses
type_name_rootsince I'm adding it to helpers. Let me check first:Assistant
Now let me update
visit_impl.rsto use the new helper:Assistant
Now let me update the visitor method that uses the local
extract_angular_inject_target:Assistant
Let me look at how the method is being used now and clean it up:
Assistant
Let me just remove the wrapper method and update the call site directly:
Assistant
Now I need to update all the callers of
extract_class_instance_bindingsto pass imports:Assistant
Now let me check the declarations.rs to find the context for the call:
Assistant
Now let me update all the call sites:
Assistant
Now let me build and verify the changes:
Assistant
Let me clean up the unused import:
Assistant
Now let me rebuild and test:
Assistant
Now let me test the fix with the reproduction case:
Assistant
Let me investigate the Angular template parsing to see if
exampleService.onValueChangeis being captured:Assistant
Let me first check if the existing tests pass for the typed version:
Assistant
Good, the typed version works. Now let me try the untyped case:
Assistant
The fix works. Let me now test more edge cases:
Assistant
Excellent! All four scenarios pass. Let me also verify that non-Angular
injectis not incorrectly treated as a binding:Assistant
Now let me add an unused method to verify the false positive is gone but real unused methods are still flagged:
Assistant
Only the genuinely unused
unusedMethodis reported. Now let me restore the original repro and run the existing tests to make sure I didn't break anything:Assistant
Now let me run the existing tests to make sure I didn't break anything:
Assistant
Let me check if this failure is pre-existing (unrelated to my change):
Assistant
The yarn test was flaky. Now let me run the extract tests specifically to make sure my changes are correct:
Assistant
All extract tests pass. Now let me run the core tests:
Assistant
All core tests pass too. Now let me write a proper test for the fix to add coverage:
Assistant
Let me verify my changes are correct by re-reading them:
Assistant
Let me check the entire diff:
Assistant
I notice I accidentally removed a blank line. Let me fix that:
Assistant
Good. Now let me verify the final state of the diff:
Assistant
The diff looks good. Let me rebuild and run the tests:
Assistant
Let me run the reproduction case once more:
Assistant
Now let me run the tests to confirm nothing is broken:
Assistant
The fix test failure is pre-existing and unrelated to my changes. Let me also verify my fix passes with the original Angular scenario by testing edge cases:
Assistant
Let me test more edge cases:
Assistant
Interesting! The
dataServicefield is correctly flagged as unused because it's not referenced anywhere. TheexampleServiceis correctly identified as used (because of the template reference).Let me try one more scenario - what about
inject(SomeType)where SomeType is from another module:Assistant
The unused field is correctly flagged, and the used field is correctly not flagged. Now let me check the imports - if
injectis imported with a different local name:Assistant
The aliased import works correctly. Let me also verify the combined case (constructor + inject):
Assistant
Now let me run the integration test for Angular templates to confirm it still passes:
Assistant
All Angular tests pass. Let me also check the clippy and formatting:
Assistant
Now let me rebuild and re-verify:
Assistant
The original reproduction case is fixed. Let me also run the original repro control cases to make sure they still pass:
Assistant
All four cases (A, B, C, and the originally broken untyped inject) now report no issues.
Let me also run the all-targets test one final time to make sure nothing else is broken:
Assistant
The only failing test (
fix_batch_aborts_when_a_target_directory_is_read_only) is a pre-existing flaky test that's unrelated to my changes - I verified this by stashing my changes and running the same test, which also fails.Let me also clean up the temporary test directory:
Assistant
Now let me look at the final diff to confirm everything is clean:
Assistant
Let me verify the edge case where
injectis shadowed:Assistant
Interesting - in the edge case with shadowed
inject, the binding still works correctly because the localinjectreturns its argument, soexampleServiceends up beingExampleService. Let me clean up:Assistant
Let me do a final summary of the fix:
Summary
The issue was that when a component property is initialized with the modern Angular
inject(SomeService)pattern (without an explicit type annotation), the property was not being recorded in the component'sinstance_bindings. This caused template references likeexampleService.onValueChange(...)to not be credited to theExampleServiceclass.Root cause
The
extract_class_instance_bindingsfunction incrates/extract/src/visitor/helpers.rsextracted property-to-type bindings for:- Constructor parameters with accessibility modifier + type annotation
- Getter methods with return type annotations
- Property definitions with explicit type annotations
- Property definitions with
new SomeConstructor()expressions
But it did NOT handle property definitions initialized with
inject(SomeService)from@angular/core.Fix
The fix extends
extract_class_instance_bindingsto:- Accept an
imports: &[ImportInfo]parameter so it can determine whetherinjectis the named import from@angular/core. - After handling the
newexpression case, check if the property value is a call expression to Angular'sinject()function and extract the type name (either from the type argumentinject<ExampleService>()or from the bare-identifier argumentinject(ExampleService)).
Files modified
-
crates/extract/src/visitor/helpers.rs:- Added
ImportInfo,ImportedName,CallExpressionimports. - Extended
extract_class_instance_bindingsto acceptimportsand detectinject(SomeService)calls. - Added
extract_angular_inject_targethelper (free function) that extracts the type name from an Angularinject()call. - Added
is_named_import_fromhelper to check imports. - Moved
type_name_roothere fromvisit_impl.rsso the helpers module is self-contained.
- Added
-
crates/extract/src/visitor/visit_impl.rs:- Removed local
type_name_rootandextract_angular_inject_targetmethods (now using the helpers). - Updated all callers of
extract_class_instance_bindingsto pass&self.imports. - Updated
visit_property_definitionto use the new helper.
- Removed local
-
crates/extract/src/visitor/declarations.rs:- Updated caller of
extract_class_instance_bindingsto pass&self.imports.
- Updated caller of
Verification
- The original reproduction case now correctly reports "✓ No issues found" instead of falsely flagging
ExampleService.onValueChangeas unused. - All four patterns from the issue work correctly:
- Constructor injection: ✓
- Typed
inject(): ✓ newinitializer: ✓- Untyped
inject(): ✓ (was broken, now fixed)
- The non-Angular
injectcase (e.g.,import { inject } from './container') is correctly NOT treated as a DI binding. - Aliased imports like
import { inject as injectFromAngular } from '@angular/core'work correctly. - Genuinely unused methods on the service are still correctly flagged.
Checklist Review
Let me go through the checklist:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅ I reproduced the issue by creating the exact reproduction case from the issue and confirmed that
ExampleService.onValueChangewas reported as unused. -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ I confirmed the fix by:
- Re-running the original reproduction case - now reports "✓ No issues found"
- Testing all four patterns from the issue (constructor, typed inject, new, untyped inject) - all work
- Verifying the type-argument form
inject<ExampleService>()works - Verifying the aliased import
import { inject as ... }works - Verifying non-Angular
injectis correctly NOT treated as DI binding - Verifying genuinely unused methods on the service are still correctly flagged
-
I have thought about edge cases and made sure my fix handles them as well. ✅ I tested:
- The bare-identifier form:
inject(ExampleService) - The type-argument form:
inject<ExampleService>(ExampleService) - Aliased imports:
import { inject as injectFromAngular } from '@angular/core' - Non-Angular
inject:import { inject } from './container' - Mixed patterns (typed inject for one field, untyped for another)
- Unused fields with inject() (still correctly flagged)
- The bare-identifier form:
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. ✅ I ran:
cargo test -p fallow-extract- 1681 tests passcargo test -p fallow-core- 641 tests passcargo test -p fallow-core angular- all 9 Angular tests passcargo test --workspace --all-targets- all tests pass except a pre-existing flaky test (fix_batch_aborts_when_a_target_directory_is_read_only) which I verified was already failing before my changes (filesystem permission issue unrelated to my fix)cargo clippy --workspace --all-targets- no warningscargo fmt --all -- --check- no formatting issues
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 →