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 the codebase.
Assistant
Now let me look at the unused_members.rs file specifically in the area where the angular template ref logic is:
Assistant
Now let's look at where the instance_bindings are extracted:
Assistant
Found it! The
extract_class_instance_bindingsfunction handles:- Constructor parameter with type annotation (
public,private, etc.) - PropertyDefinition with type annotation (
prop: Foo = ...) - PropertyDefinition with
new Foo()expression
But it does NOT handle the case where
inject(Foo)is used. Let me check the related parts to understand more:- Constructor parameter with type annotation (
Assistant
Now let me look at the
extract_class_instance_bindingsto understand the structure better and find where to add inject handling:Assistant
Now let me check existing tests to understand the patterns being tested:
Assistant
Let me also look at the
CallExpressionhandling for inject:Assistant
Now let me understand the imports and the structure of the helpers module better:
Assistant
Now let me look at the actual test cases that test injection patterns:
Assistant
Now let me look at the visit_impl.rs to see where inject is referenced:
Assistant
Now let me see how this is used at line 1886:
Assistant
Now I have a clear picture. The
extract_class_instance_bindingsfunction inhelpers.rsneeds to be updated to also handleinject(Foo)call expressions. Let me look at the part again:Assistant
Now let me check what
extract_angular_inject_targetlooks like and how it's defined:Assistant
Now let me see how
extract_class_instance_bindingsis called and how it interacts with the visitor:Assistant
Now let me understand the chain better by looking at the binding target flow:
Assistant
Now let me look at the test for the existing angular-inject-class-members fixture to see what's already working:
Assistant
Now I understand the issue. The fix needs to update
extract_class_instance_bindingsto also handleinject()calls. Let me first reproduce the issue:Assistant
Issue is reproduced. Now let me understand exactly where the fix needs to happen. Looking at the code:
Assistant
Now I understand. The function
extract_class_instance_bindings(in helpers.rs) needs to:- Check if the property is private (already does)
- Check for type annotation (already does)
- Check for
new Foo()(already does) - NEED TO ADD: Check for
inject(Foo)from@angular/core
But
extract_angular_inject_targetis a method on the visitor itself, whileextract_class_instance_bindingsis a free function. Let me look at the visitor method again:Assistant
Now I see the pattern. The visitor does it through
extract_angular_inject_targetwhich has access tois_named_import_from. Let me see howis_named_import_fromis implemented:Assistant
Now let me check what
ImportedNamelooks like:Assistant
Now let me understand how
extract_class_instance_bindingsis invoked. The visitor method has access toimportsso it knows about@angular/core. The helper function does not. Let me look at the call sites:Assistant
Let me also look at how
binding_target_namesis used in the visit_property_definition to understand the existing fix:Assistant
Now I understand the architecture. The visitor
visit_property_definitionalready handlesinject(Foo)for settingbinding_target_names(used bythis.inner.aaaresolution). Butextract_class_instance_bindingsis the free function that produces the instance_bindings used for class heritage. The two code paths are separate.Let me understand how
binding_target_namesdiffers frominstance_bindings:Assistant
So
binding_target_namesis what enablesthis.inner.aaato resolve toInnerService.aaa. Andextract_class_instance_bindingsproduces theinstance_bindingsinclass_heritage, which is used for resolving component template references likeexampleService.method()toExampleService.method.The fix is to update
extract_class_instance_bindingsto also handleinject()calls. The function is called from:visit_declaration(line 1953)visit_export_default_declaration(line 2235)declarations.rsline 61
In all cases, the visitor state (specifically
imports) is not directly passed toextract_class_instance_bindings. Let me see what's the cleanest approach:Assistant
Now let me understand more about how
inject()is detected and how it can be applied without the import context. Let me check the visitor'sextract_angular_inject_target:The key insight from the test:
#[test] fn non_angular_inject_function_does_not_map_field_member_access() { // ... import { inject } from './container'; // ... assert!( !info.member_accesses.iter().any(|a| a.object == "InnerService" && a.member == "aaa"), "non-Angular inject() should not create class-member credit" ); }So
inject()from any other module (not@angular/core) should NOT be mapped. This means we need access to the imports to verify it's from@angular/core.Let me see how to pass the imports. Let me look at the simplest approach - refactor
extract_class_instance_bindingsto optionally take anis_angular_injectpredicate function:Assistant
Now let me look at how the inject test works for typed inject to see how that is resolved currently:
Assistant
Now I need to understand how
record_typed_bindingworks to learn the pattern:Assistant
Now I have enough context. The approach I'll take is:
Solution Plan:
The fix should be in
extract_class_instance_bindingsincrates/extract/src/visitor/helpers.rs. We need to add detection ofinject(Service)calls from@angular/core.Looking at the current implementation:
- It currently extracts: constructor params with type annotation, getters with type annotation, property definitions with type annotation, and
new Foo()calls. - It does NOT handle
inject(Foo)from@angular/core.
The simplest fix: modify
extract_class_instance_bindingsto also handle the case where the property value isinject(SomeService). To check that the function isinjectfrom@angular/core, we need access to the imports.Let me modify the approach - pass an optional closure that checks for the Angular
injectfunction:Actually, looking more carefully, the cleanest approach is to:
- Add a new function
extract_angular_inject_target_from_call(call, is_angular_inject)(a free function that takes a predicate) - Modify
extract_class_instance_bindingsto accept a similar predicate and use it forinject()detection.
Let me look more at the visitor structure first to find the cleanest refactor:
- It currently extracts: constructor params with type annotation, getters with type annotation, property definitions with type annotation, and
Assistant
Now let me find a simpler approach. Looking at the test for the inject pattern that's already being correctly handled by
binding_target_names:fn extract_angular_inject_target(&self, call: &CallExpression<'_>) -> Option<String>This is in the visitor itself. The same logic can be applied in the helper. Let me check how
is_named_import_fromaccessesself.imports. I want to refactor this so the helper function gets the imports info.Actually, the cleanest way would be to:
- Extract the
inject()call detection logic into a free function that accepts the imports. - Modify
extract_class_instance_bindingsto accept the imports (or accept a closure).
Let me first take the simpler approach: make
extract_class_instance_bindingsaccept an optionalis_angular_injectpredicate.- Extract the
Assistant
Now let me look at how
type_name_rootis used and the imports of helpers.rs to understand what I have access to:Assistant
Now let me look at the existing imports in helpers.rs to see what's available there:
Assistant
OK, the helper file doesn't have access to
TSTypeReferenceimport. Let me approach this differently.Let me think about the cleanest approach. I have two options:
- Pass a closure / predicate to
extract_class_instance_bindingsthat determines if a call expression is an Angularinject()call. - Refactor to make
extract_class_instance_bindingsaccept a struct of dependencies.
Option 1 is the simplest. Let me implement it:
Now let me look at what
type_name_rootreturns and the CallExpression structure:- Pass a closure / predicate to
Assistant
Good,
TSTypeReferenceis accessible throughTSType::TSTypeReference. Now let me think about this more carefully.The most elegant solution: change the signature of
extract_class_instance_bindingsto take an optionalFn(&CallExpression) -> Option<String>predicate that returns the type name if the call is an Angularinject()call. The caller (visitor) can pass a closure that usesis_named_import_from.Actually, an even cleaner approach: just pass the imports as a parameter. But that's a bigger refactor.
Let me implement option 1 - take a predicate:
Assistant
I need to add
CallExpressionto the imports. Let me look at what oxc exposes:Assistant
OK,
CallExpressionis available. Let me check how the visit_impl handles the inject target:Assistant
Now I'll implement the fix. My approach:
- Modify
extract_class_instance_bindingsto take a generic parameter that can be a function-like closure detecting Angularinject(). - Update the 3 call sites.
Actually, the simplest approach is to use a trait-based abstraction or to simply add a parameter that takes a closure. Let me go with the closure approach using
Fn:- Modify
Assistant
Let me think again. The cleanest approach would actually be to:
- Make
extract_class_instance_bindingstake a generic predicate parameter (a closureFn(&CallExpression) -> Option<String>). - Update all 3 call sites to pass
|_| Nonefor backwards compatibility OR pass the visitor-specific closure.
Wait, looking at this more carefully,
extract_class_instance_bindingsis only ever called from within the visitor. Let me check if there's any other call site:- Make
Assistant
All call sites are in the visitor. So I can simply pass a closure from each of these. Let me design the API:
pub fn extract_class_instance_bindings<F>( class: &Class<'_>, angular_inject_target: F, ) -> Vec<(String, String)> where F: Fn(&CallExpression<'_>) -> Option<String>,Let me implement this now:
Assistant
Now I need to update the imports and refactor. Let me also check how the existing function handles
type_arguments:Assistant
Good -
call.type_argumentsis accessible directly. Now let me implement the fix:Assistant
Wait, I need to also look at the case of typed
inject()since the issue says that one already works:svc: ExampleService = inject(ExampleService);This works because the type annotation
svc: ExampleServiceis detected. The problem is only when there's no type annotation:svc = inject(ExampleService);OK, so I need to add an
else ifbranch after thenewbranch that detectsinject()calls. Let me also note that theif let Some(Expression::NewExpression(...))has acontinuemissing - actually no, it does fall through to the end of thematch. Let me also check that I follow the same pattern.Looking at the existing logic more carefully:
- Type annotation present → use type annotation,
continue(skip new/inject detection) - New expression → record
- (implicit) Fall through to nothing
I need to add: CallExpression that is
inject(Service)from@angular/core.But there's a subtle issue: the current code does NOT
continueafter detecting the NewExpression. Let me check if that's intentional... actually it does fall through because it's anif letwithoutelse if, so we should add the new condition as anelse ifor another independentif let.Let me apply the fix now:
- Type annotation present → use type annotation,
Assistant
Now I notice one issue. Looking at the existing code:
- When
newis detected, it does NOTcontinue. This is because the nextif letis forCallExpression, which won't match aNewExpressionanyway. So the lack ofcontinuedoesn't matter.
But to be safe and clear, let me add
continueto thenewbranch (so we don't accidentally match inject() on anew).Actually wait, in the existing code, the
newbranch and inject branch are different patterns (NewExpressionvsCallExpression), so they won't overlap. But I'll addcontinuefor cleanliness.Now let me apply the change:
- When
Assistant
Now let me apply the fix using the edit command:
Assistant
Now I'll apply the fix using edit:
Assistant
Let me apply the fix using the edit command.
Assistant
The edit looks good. Now I need to update the call sites. Let me update them:
Assistant
Now I'll update the call site in visit_impl.rs:
Assistant
I notice that the edit got messed up because the original lines started at 1952. Let me fix the issue:
Assistant
Now let me update the second call site:
Assistant
I see that my edit replaced 3 lines with 4 lines but missed the
let is_angular = ...line. Let me fix that:Assistant
I see I have duplicated
} else {block. Let me clean this up:Assistant
I have more cleanup to do - my edits have gotten the file structure messed up. Let me look at the current state and fix it:
Assistant
Let me fix this entire broken section:
Assistant
Now let me add the missing blank line between the functions:
Assistant
Hmm, my edits have made it worse - there's a duplicate
}and missinglet (members, super_class, ...)line. Let me use git to restore:Assistant
Let me revert visit_impl.rs and reapply the changes more carefully:
Assistant
Good, the helpers.rs change is intact. Now let me update the visit_impl.rs call sites one at a time more carefully. First, let me see the current state:
Assistant
Now let me update the second call site:
Assistant
Now let me update the third call site (in declarations.rs):
Assistant
I see that
CallExpressionis already imported in declarations.rs. Let me update the call site:Assistant
Wait, but
extract_angular_inject_targetis defined onModuleInfoExtractor(the visitor struct). Let me check if it's accessible fromdeclarations.rs:Assistant
Since both
declarations.rsandvisit_impl.rsare in the samevisitormodule andextract_angular_inject_targetis defined as a method onModuleInfoExtractorin visit_impl.rs, it should be accessible. Let me verify:Assistant
extract_angular_inject_targetis defined at line 1637, which is within theimpl<'a> Visit<'a> for ModuleInfoExtractorblock. Let me check if it's accessible fromdeclarations.rs. Since they're both methods on the sameModuleInfoExtractorstruct, the answer should be yes.Let me build to check:
Assistant
I need to make it public (or pub(crate)). Let me change it to pub(crate):
Assistant
Now let me try to build again:
Assistant
Let me run the reproduction again:
Assistant
Hmm, the issue is still happening. Let me investigate - maybe my changes don't actually get applied or the test setup doesn't exercise them. Let me check the template ref resolution path again:
Assistant
Now let me trace through this. We need:
angular_tpl_chain_accessesto contain(exampleService, onValueChange)from the example.component.ts fileclass_heritage_by_filefor example.component.ts to haveinstance_bindings: [("exampleService", "ExampleService")]
Let me check that the second part is now happening. Let me look at the issue more carefully by adding some debug output:
Wait, I realize the issue! The chain accesses happen from the resolved import module (the template HTML file is processed via
extract_angular_tpl_chain_accesses). But the templateexampleService.onValueChangeis processed against the component file. Let me look at the angular_tpl_chain_accesses logic again:Assistant
Now I see - the template url itself adds an import (a side-effect import), but the template references are added to
member_accessesof the same file (the component file) asANGULAR_TPL_SENTINELaccesses.Let me trace this more carefully. In the component file:
- The template is added as a SideEffect import (the templateUrl)
- The template references are added to
member_accessesfor the same file (component file)
So in
unused_members.rs, when we look atresolved_modules:angular_tpl_chain_accessesfor the component file should contain("exampleService", "onValueChange")class_heritage_by_filefor the component file should containinstance_bindings: [("exampleService", "ExampleService")]
Let me check how the templateUrl is processed:
Assistant
Hmm, so for an external template URL, the template is NOT processed for refs. The refs are only collected for inline templates. The
template_urlonly registers an import. So the template reference detection must work via the html parser. Let me check:Assistant
So when the HTML file is parsed, its template refs are added as member accesses with
ANGULAR_TPL_SENTINEL. But these refs are stored on the HTML file's ModuleInfo, NOT the component file's ModuleInfo.Then in
unused_members.rs:angular_tpl_chain_accessesiterates overresolved_modules(which includes both .ts and .html files)- For each
ResolvedModule, if it has a sentinel access, it collects the chain accesses - Then it iterates over resolved modules and looks at their
class_heritage_by_file - For each resolved module, for each resolved import whose target is the file with chain accesses, it applies the bindings
So:
- The HTML file
example.component.htmlhas the chain accesses (withANGULAR_TPL_SENTINELsentinel) - The component file
example.component.tsshould have theclass_heritagewithinstance_bindings: [("exampleService", "ExampleService")] - The component file imports the HTML file (via templateUrl)
Let me re-read the
unused_members.rslogic:Assistant
OK so
class_heritage_by_fileis the mapping ofFileId -> &[ClassHeritageInfo]. The component file'sclass_heritageshould haveinstance_bindings.Now my fix should have made this happen. Let me debug - maybe the issue is that
extract_angular_inject_targetis not being called properly. Let me add a quick debug test:Wait, let me first verify the fix is actually applied:
Assistant
OK the helpers.rs has my fix. Now let me check the call sites in visit_impl.rs:
Assistant
OK, the changes are in place. Let me trace through more carefully. Let me add a debug print to see what's happening:
Actually, let me look at how the test for
angular-inject-class-membersworks since it does work (the existing fixture passes):Assistant
This fixture uses
this.inner.aaa- the existing fix forbinding_target_namesalready handles this. The template url case is different. Let me trace the call path for the component class:Assistant
Now let me understand the relationship between
visit_classandvisit_declaration:Assistant
OK, I see the structure now. Let me find how visit_class is called:
Assistant
Hmm, the only
visit_classis the one I see. It's the AST visitor. Nowvisit_declarationis also called from the AST visitor. So we have two paths:visit_class- runs the AST walk, adds template URLs as importsvisit_declarationforClassDeclaration- extracts class members and instance bindings
Both should be called for the same class. Let me check the order by looking at how
walk::walk_classcalls things:Assistant
Now
walk::walk_declaration(self, decl)for a class would callwalk_class, which would call our overriddenvisit_class. Sovisit_declarationis called first, thenvisit_class.Now let me check the issue more carefully. When
visit_declarationis called for our component, it hasself.importspopulated with whatever has been processed so far. Let me look at what has been processed before:Assistant
OK so imports are pushed when visiting the import statements. Since
visit_declarationfor the class is called AFTERvisit_import_declaration, the imports are already populated by the time we callextract_class_instance_bindings. So my fix should work...Let me try adding some debug output to see what's happening:
Assistant
Actually, let me first run the existing tests to make sure my fix doesn't break anything:
Assistant
All extract tests pass. Now let me test the integration test for the inject fixture:
Assistant
The test passes. Now let me re-check the reproduction - I need to make sure my changes are actually applied to the binary:
Assistant
Still failing. Let me trace more carefully. Let me check if
extract_class_instance_bindingsis actually being called for the component class:Assistant
The issue still exists. Let me debug by checking if the issue is in the
unused_members.rsflow or in theextract_class_instance_bindingsflow. Let me add a debug print:Assistant
Let me add a quick debug print to see if the binding is being created:
Assistant
Let me add a debug eprintln to trace what's happening:
Assistant
I see I made a mess - the new code got inserted in the wrong place. Let me revert and apply more carefully:
Assistant
Now let me apply the fix more carefully:
Assistant
Now I need to add the inject call detection after the new expression detection:
Assistant
I see - I lost the closing braces! The replacement removed the closing
}ofClassElement::PropertyDefinitionarm and thematchand thefor. Let me fix this:Assistant
Now let me verify the build works:
Assistant
Now let me test the reproduction:
Assistant
Still failing. Let me add a debug eprintln to see what's happening:
Assistant
The DEBUG message didn't print. That means the
extract_class_instance_bindingsfunction isn't being called for ourExampleComponent. Let me check the visitor path:Assistant
Debug print is there but didn't fire. Let me check the debug at the function entry point:
Assistant
I made a mess again. Let me revert and start fresh:
Assistant
Now let me carefully apply the change using a single edit:
Assistant
Now let me add the inject call detection:
Assistant
Now let me build and check:
Assistant
Still failing. Let me add an eprintln to understand:
Assistant
The debug print is not appearing at all. This means
extract_class_instance_bindingsisn't being called for theExampleComponent. Let me look at the call site flow:Assistant
Let me check whether there is something I'm missing about the visit_declaration path. Maybe the component class is processed via
extract_declaration_exports:Assistant
extract_declaration_exportsis called fromvisit_export_named_declaration(forexport class Foo {...}). The ExampleComponent is exported, so this path would be taken. Let me add debug print there:Assistant
Let me add debug here:
Assistant
The debug print doesn't fire! So neither declarations nor the helpers function is being called for the ExampleComponent. Let me check the visit_declaration path:
Assistant
None of my debug prints are firing! This is strange. Maybe the module isn't being parsed. Let me try a different approach:
Assistant
OK, the tool runs. Let me check if there's caching preventing rebuild:
Assistant
The debug eprintln isn't being printed. This is weird. Maybe stderr is being suppressed? Let me check:
Assistant
No debug output at all in stderr. So neither
extract_class_instance_bindingsnorvisit_declarationare being called for the ExampleComponent. Let me check if the .ts files are even being processed:Assistant
Let me add an eprintln at the visitor entry point:
Assistant
Let me add debug here:
Assistant
Even
visit_programdebug doesn't fire! Something is really wrong. Let me check whether the binary is actually the new one:Assistant
The string is in the binary. So the binary is up to date. Why isn't it printing? Maybe the file is being cached or the analysis pipeline isn't even running. Let me look at the parse.rs to see where the visitor is used:
Assistant
OK so the visitor is called. Let me add a debug print in
parse_source_to_module_inner:Assistant
I duplicated the code. Let me revert:
Assistant
Let me try with a sed approach to insert a single line:
Assistant
Still no debug output. This means the file is being processed but somehow my debug isn't appearing. Wait - maybe
parse_source_to_module_innerisn't even being called, because the files are being parsed by a different code path. Let me search:Assistant
There's a cache. Maybe the cache is preventing re-parsing. Let me look at it:
Assistant
There's a cache! Let me find where the cache is stored:
Assistant
Found the cache! Let me clear it and try again:
Assistant
Excellent! The fix works! "✓ No issues found"! The cache was the issue. Let me clean up the debug prints and verify the fix:
Assistant
Good. Now let me clean up the debug prints in other files:
Assistant
Good, all debug prints removed. Now let me rebuild and test:
Assistant
The fix works. Now let me check the other cases from the issue (A, B, C) to make sure they still work:
Assistant
Control A still works. Now let's test Control B:
Assistant
Control B still works. Let's test Control C:
Assistant
Control C still works. Let me also test the original repro (untyped inject):
Assistant
Now let me think about edge cases:
- Untyped
inject(SomeService)from@angular/core- ✅ Fixed - Untyped
inject(SomeService)from non-@angular/core- Should NOT be treated as instance binding - Untyped
inject<T>(SomeService)with explicit type arg - Should be treated as instance binding - Property assigned from
inject()via constructor parameter inject(SomeService)on a private property - Should NOT be treated (private accessibility check)
Let me test some of these edge cases. First, let me test that the
non_angular_inject_function_does_not_map_field_member_accesstest still passes:- Untyped
Assistant
Now let me test some more edge cases manually:
Assistant
Non-
@angular/coreinject()is correctly NOT mapped to instance binding. (The unresolved imports are because./my-containerdoesn't exist, but that's not relevant.)Let me also test with
inject<T>(Service)syntax:Assistant
Hmm, that works too because the existing
extract_angular_inject_targetalready handles the<ExampleService>type argument. Let me confirm by looking at it again:Assistant
The function checks
<ExampleService>first and then the identifier argument.Let me also test with private property to verify it doesn't create an instance binding:
Assistant
usedInTemplate()is correctly NOT reported as unused (since it's used in the template), andunusedServiceMethodIS correctly reported. The fix is working as expected.Let me also verify the existing
angular-inject-class-membersfixture still passes:Assistant
Now let me run all tests to make sure I didn't break anything:
Assistant
That test failure is unrelated to my fix. Let me verify:
Assistant
Hmm, the test name was different. Let me try with my changes:
Assistant
The test name might have been filtered out. Let me check:
Assistant
The test passes when run in isolation. It's a flaky test or order-dependent test. Let me run all the tests for the extract and core crates to ensure I haven't broken anything:
Assistant
All 641 core tests pass! Now let me also run the graph tests:
Assistant
All 48 graph tests pass. Now let me also run the cli tests:
Assistant
Let me check if this is unrelated:
Assistant
Confirmed - the test failure is unrelated to my changes. It's a pre-existing issue (probably environment-specific since it tries to make a directory read-only, which doesn't work as root).
Let me now run the full cli tests except for the failing one:
Assistant
All 1830 lib tests pass. Now let me think about additional edge cases I should test:
- Property with both type annotation AND
inject()initializer - should use type annotation (since it has higher priority in the existing code) - Static property - should not create binding
- Method/constructor assignment with
inject()- should not apply (only applies to PropertyDefinition)
Let me look at the current code to verify:
- Property with both type annotation AND
Assistant
The code only handles
PropertyDefinitionand notstaticproperties. Thestaticproperties don't havestatic_name()returning their name in the same way. Let me check if there are static handling:Assistant
Static properties aren't explicitly excluded, but
static_name()returnsSomefor both instance and static properties. The existing code doesn't filter for static, so my code doesn't either - which is consistent.Let me test the edge case where the type annotation AND inject() are both present:
Assistant
The type annotation
ExampleServiceis used. BothsomeMethodis correctly NOT reported (used in template). The other two methods are correctly reported as unused. So the type annotation takes priority.Let me also test the untyped inject with
inject<ExampleService>():Assistant
Hmm! That's a problem. With
inject<ExampleService>(ExampleService), the binding is NOT being created. Let me check the extract_angular_inject_target:Assistant
The function does check
type_argumentsfirst. Hmm, why isn't it returning "ExampleService"? Let me check theis_named_import_from- maybe the issue is that the file isn't being parsed correctly.Actually wait, the existing
binding_target_namestest for inject would have used the same code path. Let me re-run the original test:Assistant
Let me re-check the issue with
inject<ExampleService>(ExampleService). Maybe the issue is the cache:Assistant
Still failing. Hmm. Let me add a debug eprintln to see what's happening:
Assistant
Wait! Now it's working. Only 2 unused members are reported (anotherMethod and unusedServiceMethod), not all 3. The issue must have been the cache. Let me confirm with a fresh test of the original problem:
Assistant
Working. Now let me also re-test the explicit type arg case:
Assistant
Working too. The earlier failure was just due to caching - now with a clean cache, both forms work.
Let me clean up the debug eprintln:
Assistant
Now let me also look at if there's anything I should test with non-angular inject (my implementation correctly returns None from extract_angular_inject_target, so it's fine).
Let me also consider this edge case: what if the same property has type annotation AND
inject()but the type annotation is different? For example,prop: Foo = inject(Bar). The current code prefers the type annotation. Let me test:Assistant
With type annotation
any, it's still no issue. That means the type annotation is used (which is "any") and not ExampleService. But since the property is template-accessible, the template can access it, so the unused member is correctly not reported.Wait, that's interesting. With
: any, the template reference still works because theanyis what's stored as the binding. Let me trace through:Actually, looking at the unused_members.rs code, the
component_bindingsis(exampleService, "any"). The template accessexampleService.someMethodbecomes(any, someMethod). The local_to_export_keys for "any" wouldn't match anything, so... let me re-check. Actually, theinstance_bindingsis processed bypropagate_accesses_through_typed_instance_bindings. So even though "any" isn't a class, the access might still propagate through the bindings.Let me look more carefully:
Assistant
This is for normal
this.foo.bar()resolution. There's also theangular_tpl_chain_accesseslogic that uses theclass_heritage(which is theinstance_bindingsfrom my fix). Let me check what happens withany:In the angular_tpl_chain_accesses code, it uses
component_bindingsfromclass_heritage_by_file. If the type isany, thencomponent_bindingsis(exampleService, "any"). Thenlocal_to_export_keys.get("any")returnsNone, so it doesn't propagate.But the test showed "No issues found"! That's strange. Let me check more carefully:
Assistant
Yes, "No issues found". Maybe
anyhas some special handling. Actually, that's because the type annotationanyis probably treated as the un-typed case. Let me see what happens if I use a non-existent type:Assistant
OK now it reports the unused member. So with a non-existent type, the type annotation takes priority and the binding is not to ExampleService. The case of
anymust be specially handled somewhere in the extract_typed_bindings logic.Let me search for
anyhandling:Assistant
No special handling for
any. The "No issues found" for: anyis a pre-existing behavior I shouldn't worry about. My fix doesn't affect it.Let me now also think about another edge case. What about when the inject() call is for a different module's
inject?Actually, I already tested that - non-Angular
inject()is correctly NOT mapped.Let me also think about: what if
extract_angular_inject_targetreturns a type that's actually a generic type parameter? In the existing logic, it returns the name as-is, andresolveis then called.resolvewould either keep it or replace it with the type param constraint. Let me check:Assistant
OK so the resolve closure will replace generic type params with their constraints, or pass through as-is. This is correct for inject() too.
Now let me also test the case where inject is called with a generic that has a constraint:
Assistant
SpecialService.specialMethodis correctly NOT reported (it's used via the template). OnlyBaseServiceis reported as unused export.Now let me also verify that a few other potentially related tests still pass. Let me run all extract tests:
Assistant
All 1681 tests pass. Now let me write a new test for the specific issue we're fixing. Wait, the rules say I should not add new tests to the repository. Let me create a temporary test instead:
Actually, looking at the task description:
UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository.
OK, I should not add new tests. The fix is verified by the existing tests passing and the reproduction case working.
Let me also re-run the existing angular_inject integration test to confirm:
Assistant
All angular tests pass! Let me also verify with a final check that the original repro still works:
Assistant
The fix is working correctly. Let me do a final review of all my changes:
Assistant
I see my sed command removed a comment line in visit_impl.rs. Let me restore that:
Assistant
Now let me run cargo fmt and clippy to make sure the code is clean:
Assistant
Let me run clippy:
Assistant
Clippy suggests collapsing the if. Let me fix:
Assistant
Clippy passes. Now let me also run cargo build to confirm:
Assistant
Let me run the original reproduction one more time:
Assistant
The fix is working correctly. Now let me do a final review:
Assistant
The diff is clean. Let me also verify by looking at the final code:
Assistant
The code looks clean. Let me run the entire test suite once more to be confident:
Assistant
All 5389 tests pass across the extract, core, and graph crates. Let me check the cli tests too:
Assistant
All 1830 lib tests in cli also pass. Let me also check the full test run for cli:
Assistant
Only the
fix_batch_aborts_when_a_target_directory_is_read_onlytest fails, and I already verified that's a pre-existing issue unrelated to my changes (it's a test that tries to make a directory read-only, which doesn't work as root).Let me verify by checking if this test also fails on the original code:
Assistant
Confirmed - the test failure is pre-existing and unrelated to my changes.
Let me now also remove the temporary repro folder:
Assistant
Now let me do a final check of all my changes:
Assistant
Now let me list the checklist:
Checklist:
-
If an error was reported in the issue description, I have successfully reproduced it. - I successfully reproduced the issue. The error was a false positive reporting
ExampleService.onValueChangeas unused when the property is initialized withinject(ExampleService)(no type annotation). -
If an error was reported in the issue description, I have confirmed that my fix resolves the error. - After my fix, the original repro now reports "✓ No issues found".
-
I have thought about edge cases and made sure my fix handles them as well. - I tested:
- The original untyped
inject(Service)case (the bug) - Control A: constructor injection (
public svc: Service) - still works - Control B: typed
inject(svc: Service = inject(Service)) - still works - Control C:
new Service()initializer - still works - Non-
@angular/coreinject()- correctly NOT mapped (preserves existing behavior) inject<Service>(Service)(explicit type arg) - correctly mappedinject()with type annotation (combination) - type annotation takes priority- Inheritance hierarchies (BaseService/SpecialService)
- Genuinely unused service methods still reported
- The original untyped
-
I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. - All existing tests in
fallow-extract(1681),fallow-core(641),fallow-graph(48), andfallow-cli --lib(1830) pass. The only test that fails is a pre-existing test failure unrelated to my changes (test name:fix_batch_aborts_when_a_target_directory_is_read_onlywhich fails because the test tries to set a directory as read-only, which doesn't work when running as root).
Let me also do one more check that the fix is properly applied:
-
Assistant
The diff is clean and focused. Let me now do one more final verification:
Assistant
The fix is working correctly. The repro now reports "✓ No issues found" as expected.
Let me clean up:
Assistant
Now let me also check the final list of changes:
Assistant
Summary
Issue: The
angularplugin's dead-code detector reports a service method as unused when it's only referenced from an external Angular HTML template (prop.method()), and the component propertypropis initialized with the moderninject()pattern without an explicit type annotation (e.g.,readonly exampleService = inject(ExampleService);).Root Cause: The
extract_class_instance_bindingsfunction incrates/extract/src/visitor/helpers.rsis responsible for extracting instance bindings from class members. It already handles:- Constructor parameter properties with type annotations
- Getter methods with return type annotations
- Property definitions with type annotations
- Property definitions with
new Foo()initializer
But it was missing the
inject(Foo)pattern (when there's no explicit type annotation). The visitor already hadextract_angular_inject_targetmethod that detects Angularinject()calls, but it was only used forbinding_target_names(which handlesthis.field.method()accesses in code), not forinstance_bindings(which handles template references likefield.method()in HTML).Fix:
- Modified
extract_class_instance_bindingsincrates/extract/src/visitor/helpers.rsto accept a generic predicateF: Fn(&CallExpression<'_>) -> Option<String>that detects Angularinject()calls. - Added a new branch in the function that detects
inject(Foo)calls (after the existingnew Foo()branch) and uses the predicate to extract the type name. - Updated all 3 call sites to pass a closure that calls
self.extract_angular_inject_target:crates/extract/src/visitor/visit_impl.rs(2 call sites)crates/extract/src/visitor/declarations.rs(1 call site)
- Made
extract_angular_inject_targetmethodpub(crate)so it can be called fromdeclarations.rs(in the same module).
The fix:
- Resolves the original issue: untyped
inject(Service)now creates the correct instance binding. - Maintains backward compatibility: all existing cases (constructor injection, typed
inject,newinitializer) still work. - Properly checks that the
injectis from@angular/core(via the existingis_named_import_fromcheck insideextract_angular_inject_target), so non-Angularinject()functions are not incorrectly mapped.
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 →