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);
-
Assistant
I'll start by exploring the repository structure to understand the codebase and then locate the Angular plugin code that handles template references.
Assistant
Let me explore the repository structure more to understand how it's organized, especially looking for the Angular plugin.
Assistant
This is a Rust project. Let me look at the crates directory to find the Angular plugin code.
Assistant
Let me search more specifically for "angular" plugin related files:
Assistant
Great! Let me examine the Angular plugin file and the template extraction code:
Assistant
Now let me look at the Angular template extraction code:
Assistant
Now let me look at the integration test file for Angular template members to understand how the component property to service type binding works:
Assistant
Now let me look at the test fixtures to understand how they set up component/service relationships:
Assistant
Let me look at the component and service files in this fixture to understand how the binding works:
Assistant
Now I need to find where the component property to service type binding happens. The issue is that when a property is initialized with
inject()without a type annotation, the type is not resolved. Let me search for where this binding is done:Assistant
Let me search for where the template references are resolved against component properties:
Assistant
Let me look at the unused_members.rs file, specifically the part that handles Angular template references:
Assistant
Command was interrupted. Let me search more specifically for the part of the code that handles Angular template references and resolves them to component properties. )
<tool_call> <function=bash_terminal> <parameter=command> grep -n "ANGULAR_TPL_SENTINEL" /fallow/crates/core/src/analyze/unused_members.rs </tool_call>
Assistant
Let me try the grep command again without the typo.
Assistant
Let me look at the sections around those line numbers to understand how Angular template references are resolved. The key sections are around line 1439 where the filtering happens.
Assistant
Now I understand the flow. The code is looking at
component_bindingswhich comes fromclass_heritageand specificallyinstance_bindings. Let me understand whatinstance_bindingsis and where it's populated from.The key logic is:
angular_tpl_chain_accessescollects member accesses from Angular templates where the object is NOT the sentinel (so it's a component property likeexampleService)- For each component file, it gets
component_bindingsfromclass_heritagewhich maps property names to their types - Then it looks up the type in
local_to_export_keysto find the export key for that type - Finally, it credits the member access to that export key
The issue is that
instance_bindingsis not being populated for untypedinject()initializers. Let me find whereinstance_bindingsis populated.Now I need to find where
instance_bindingsis populated. This is likely in the extract crate.Assistant
Let me look at the
extract_class_instance_bindingsfunction which is where the bindings are extracted.Assistant
I found the issue. The
extract_class_instance_bindingsfunction handles:- Constructor parameters with accessibility modifiers
- Getters with return type annotations
- Property definitions with type annotations
- Property definitions with
newexpressions
But it does NOT handle
inject()call expressions! Let me look at what AST pattern we need to match:Assistant
I found the issue! In
extract_class_instance_bindings, the code handles:- Constructor parameters with accessibility modifiers
- Getters with return type annotations
- Property definitions with type annotations
- Property definitions with
newexpressions
But it does NOT handle
inject()call expressions. Let me first create a reproduction script to confirm the issue:Assistant
The previous command created the package.json file. Now I need to create the rest of the reproduction files to confirm the issue exists before I fix it.
Assistant
ok continues
Assistant
continuing to create the reproduction files
Assistant
continuing to create reproduction files
Assistant
good, continuing to create the reproduction files
Assistant
Now I need to build the fallow binary and run it to reproduce the issue. Let me check how to build it first:
Assistant
Now let me build the CLI and run it to reproduce the issue:
Assistant
Good, the build succeeded. Now let me run fallow on the reproduction case to confirm the issue exists. )
Assistant
I've confirmed the issue. Now I need to fix the
extract_class_instance_bindingsfunction to handleinject()call expressions. The fix needs to extract the type from the argument of theinject()call.Assistant
Now let me look at the full
extract_class_instance_bindingsfunction and understand how to add support forinject()calls. The fix should detect when a property is initialized withinject(SomeType)and extractSomeTypeas the binding type.Assistant
Now I understand the issue. In
extract_class_instance_bindings, the code handles:- Constructor parameters with accessibility modifiers
- Getters with return type annotations
- Property definitions with type annotations
- Property definitions with
newexpressions
But it does NOT handle
inject()call expressions. According to the issue, when a property is initialized withinject(ExampleService)without an explicit type annotation, the function doesn't extract the binding.Let me look at the existing test cases to understand the expected behavior better:
Assistant
Now I understand the codebase well. Let me look at how CallExpression is structured in the AST so I can properly detect
inject(ExampleService):Assistant
Now I understand the issue. The function handles
NewExpressionfor things likenew ExampleService(), but it doesn't handleCallExpressionforinject(ExampleService). I need to add support for detecting when a property is initialized withinject(SomeType).Let me look at what imports are available and how to check for inject calls:
Assistant
Now let me look at the fix. I need to add handling for CallExpression with
inject()in the PropertyDefinition arm. Let me check the structure of a CallExpression in oxc_ast:Assistant
Let me find the definition of
is_builtin_constructorto understand how it works:Assistant
Now I understand the issue. The
extract_class_instance_bindingsfunction handles:- Constructor parameters with accessibility modifiers
- Getters with return type annotations
- Property definitions with type annotations
- Property definitions with
newexpressions (line 682)
But it does NOT handle
inject(Type)call expressions. I need to add support for detecting when a property is initialized withinject(SomeType).Let me make the fix:
Assistant
I see the edit removed some important code. Let me fix this properly:
Assistant
I see I broke the file. Let me revert it and make the correct fix:
Assistant
Now let me carefully look at the structure and make the correct fix. The issue is that after handling
NewExpression, I need to also handleCallExpressionforinject()calls.Assistant
Now I need to add code to handle
inject(Type)call expressions after thenewexpression handling. The fix should:- Check if the property value is a
CallExpression - Check if the callee is an identifier with name "inject"
- Extract the first argument as the type name (which should be an identifier)
Let me write this properly.
- Check if the property value is a
Assistant
I see the edit command removed the
NewExpressionhandling code and the closing brace forClassElement::PropertyDefinition. Let me revert and try again with the correct indentation:Assistant
Now let me try again with the correct edit, making sure to preserve the existing code and add the new inject() handling:
Assistant
Now let me use the replace command to replace the existing new expression handling with the expanded version that also handles inject():
Assistant
I can see the exact lines now. Let me make the edit properly:
Assistant
The edit was successful! Now I can see the new code for handling
inject()calls has been added. Let me rebuild and test:Assistant
Build succeeded. Now let me run fallow on the reproduction case to verify the fix works:
Assistant
The issue is still occurring. Let me check if the issue might be elsewhere. The template reference should be credited properly. Let me debug by looking at how the template references are being resolved.
Let me trace through the logic more carefully:
- The template scanner finds
exampleService.onValueChangeand creates a member access with object=exampleServiceand member=onValueChange - The
angular_tpl_chain_accessescollects this - The code then looks at
component_bindingsfromclass_heritagewhich should mapexampleServicetoExampleService - The type name is looked up in
local_to_export_keysto find the export key forExampleService - The member access is credited to that export key
The issue is that step 3 depends on
instance_bindingsbeing populated. Let me add a test to verify thatinject()is being handled correctly in the extract phase:- The template scanner finds
Assistant
I need to verify that my fix for handling
inject()calls in theextract_class_instance_bindingsfunction is working correctly. The build succeeded, but the reproduction test is still failing. Let me check if there's an issue with how I'm detecting theinject()call. I should look at the test files to understand how to properly test this functionality and verify that the binding is being extracted correctly.Assistant
Let me look at the existing tests for instance_bindings to understand the expected behavior better:
Assistant
Now I understand! There are already tests for
inject()that work in some cases. Let me look more carefully at how the inject() binding is being handled in those tests. The key insight is that there's a different mechanism for handling inject() calls - it's using thepropagate_accesses_through_typed_instance_bindingsfunction, not justinstance_bindings.Let me search for how
inject()is handled more broadly:Assistant
Now I see my code was added. Let me also search for where the inject() call is handled for member access mapping:
Assistant
Good catch! There's already an
extract_angular_inject_targetfunction. Let me look at how it's being used:Assistant
I see! There's already a mechanism in
visit_impl.rsthat handlesinject()from@angular/core. The key is that it usesis_named_import_fromto verify thatinjectis actually from@angular/core. This is important because the test "non_angular_inject_function_does_not_map_field_member_access" shows that we should NOT map inject calls that are not from Angular.Let me check how this is used and why the instance_bindings approach I added might not be sufficient:
Assistant
Looking at this code, I see that the
visit_impl.rsalready handlesinject()calls usingbinding_target_namesfor regular member access resolution. But the issue is thatinstance_bindings(used for template resolution) doesn't includeinject()calls.Let me check if there's an Angular context check available:
Assistant
Let me look at this function and understand how to use it:
Assistant
Let me look at the extract_class_instance_bindings function signature to understand how it can check for Angular context:
Assistant
I need to check if the class has an Angular decorator before adding the inject() binding, similar to what the visit_impl.rs code does. Let me update the fix:
Assistant
I see the issue now! Looking at the test "non_angular_inject_function_does_not_map_field_member_access", the code needs to only apply the inject() mapping when the class has an Angular decorator. But my current implementation doesn't check for that.
However, looking at the
extract_class_instance_bindingsfunction, it takesclass: &Class<'_>as a parameter, so I can check if the class has an Angular decorator before adding the binding. Let me update the code:Assistant
The code looks correct now. Let me rebuild and test:
Assistant
...
<tool_call> <function=bash_terminal> <parameter=command> cd /fallow/repro && /fallow/target/release/fallow dead-code --config .fallowrc.json </tool_call>
Assistant
The previous command was not executed properly. Let me try again to run the fallow CLI on the reproduction directory.
Assistant
I see the issue is still occurring. Let me debug this by checking if the
instance_bindingsare being extracted correctly. Let me run the extract tests first to see if my changes are working:Assistant
Let me search for existing tests related to instance_bindings:
Assistant
Let me search for tests related to Angular inject in the visitor tests:
Assistant
Let me run the existing Angular inject tests to see if they pass:
Assistant
The existing test
angular_inject_field_maps_this_field_member_accesspasses. This test is checking thatthis.inner.aaais mapped toInnerService.aaa. But that's a different mechanism - it's usingbinding_target_namesnotinstance_bindings.The issue is about template references, which use
instance_bindingsto resolve the type of component properties. Let me look at the existing tests for Angular template members to understand what's expected.Let me run the integration tests related to Angular templates to see if they pass.
Assistant
The existing test passes. Let me look at the fixture that's being tested and understand why the untyped inject() case isn't working. Let me check the fixture files:
Assistant
Let me investigate further by adding a test case to verify the inject() extraction is working:
Assistant
I see - the test shows that
this.inner.aaais being mapped toInnerService.aaausingbinding_target_names. But the issue is about template references, which useinstance_bindingsfromclass_heritage.Let me look at the test that specifically tests template member resolution:
Assistant
Let me run all the tests in the fallow-extract crate to make sure my change doesn't break anything:
Assistant
All tests pass! Now let me run the core tests as well:
Assistant
Let me create a temporary test script to verify my fix is working:
Assistant
Let me instead write a proper unit test to verify that inject() bindings are being extracted. Let me look at the existing tests for instance_bindings:
Assistant
Let me look for tests that specifically check the
class_heritageandinstance_bindingsto understand how they're being tested.Assistant
Let me search for tests that check class_heritage and instance_bindings properly.
Assistant
Let me look at one of these tests to understand how class_heritage and instance_bindings are tested.
Assistant
Now I understand how to test
instance_bindings. I can see that the test checksclass_heritageforinstance_bindings. Let me write a simple test to verify that my fix is working - specifically thatinject(ExampleService)creates an instance binding.But first, let me check if there's an issue with how the component file is being parsed. The reproduction case has:
- A component file with
inject(ExampleService) - A template file that references
exampleService.onValueChange
The issue is that the template reference should be credited to the service method. Let me trace through the code more carefully to see what's happening.
Looking at the code in
unused_members.rsaround line 1513:angular_tpl_chain_accessescollects member accesses from Angular templates where the object is NOT the sentinel
- A component file with
Assistant
Let me try the bash command again to check the existing tests for instance_bindings.
Assistant
Let me verify that my fix is actually in place by checking the current state of the helpers.rs file:
Assistant
Now let me verify the fix is working by running the tests and checking if the inject() binding is being extracted:
Assistant
All tests pass. Now let me run the reproduction case again to verify the fix works.
Assistant
Let me check the Angular template scanner to understand how member accesses are being collected:
Assistant
Let me add a simple unit test to verify that
inject()is being extracted as an instance binding:Assistant
Let me add the test to the actual test file and run it to verify the fix is working.
Assistant
Let me find the end of the test file to add my test:
Assistant
Let me add the test at the end of the file:
Assistant
Actually, let me continue with my thought. I was about to add a test and run it to verify the fix. Let me run the test I just added.
Assistant
The test passes, confirming that
inject()is now being extracted as an instance binding. However, the reproduction case is still failing. Let me investigate why the template references aren't being connected to the instance binding.Let me check how external templates are resolved and whether the template file's references are being attributed to the component file:
Assistant
Let me trace through the logic of how Angular template references are resolved to see why my fix isn't working end-to-end:
Assistant
Let me trace through the logic more carefully. The code is looking at
resolved.all_resolved_imports()but Angular HTML templates are not imports - they're resolved viatemplateUrlin the component decorator. Let me check how external templates are linked to their component files.Assistant
Let me search for how external Angular templates are linked to their component files and how their references are resolved.
Assistant
Let me investigate how Angular template files are linked to their component files in the graph.
Assistant
The user is reminding me that I need to use proper tool calls. Let me continue investigating the issue by searching for how Angular templates are linked to components.
Assistant
Let me trace through the code to understand how Angular template files are connected to their component files. The
has_angular_component_template_urlflag seems important. Let me search for how this is used.Assistant
Let me investigate how the graph connects Angular component files to their template files:
Assistant
Let me examine how external Angular template files are linked to their component files in the graph:
Assistant
Let me investigate how the Angular template file is linked to its component file in the module graph:
Assistant
Let me trace through how Angular template files are connected to their component files in the graph.
Assistant
You're right, I need to properly format my response. Let me continue investigating the issue by examining how Angular template files are connected to their component files.
Assistant
Let me trace through how Angular template files are linked to their component files. The key is understanding how the graph connects the HTML template file to the component TypeScript file, so that template references can be credited to the component's instance bindings.
Let me search for how the Angular template URL is resolved and linked to the component.
Assistant
The user is asking me to make a function call. I need to continue investigating how Angular templates are linked to component files. Let me search for how the graph resolves and links HTML template files to their component TypeScript files.
Assistant
Let me understand how the template file is connected to the component file by examining the import structure:
Assistant
Let me trace through how Angular template references are converted to member accesses:
Assistant
Now I see! The Angular template refs are collected in
visit_impl.rsat line 3053. Let me examine how those refs are attached to the module and how they flow through the analysis pipeline.Assistant
I see now - the Angular template refs are collected for inline templates (templates defined in the component decorator). But the issue is about external templates (templateUrl). The external template is resolved as a separate file, and its member accesses should be connected to the component file's instance bindings.
Let me check how external template files are handled:
Assistant
Let me trace how external Angular templates (referenced via
templateUrl) are resolved and connected to their component:Assistant
Looking at the code, I can see that:
- The external template URL is added as a side-effect import from the component file
- The analysis looks at
angular_tpl_chain_accesseswhich contains member accesses from the template file - It then tries to resolve those accesses through the component's
instance_bindings
My fix adds
inject(ExampleService)to the instance bindings. Let me verify this is working by checking if the analysis code is correctly finding the bindings. Let me run the existing tests to make sure everything passes:Assistant
Wait, I need to continue testing. The user is reporting an error about a malformed function call, but I didn't make one. Let me continue investigating the issue.
Assistant
The user's message was empty, so I need to continue investigating. Let me rebuild the release binary and test the reproduction case again to confirm if my fix works:
Assistant
The user sent an empty message, which means they want me to continue my work. Let me check the reproduction case to see if my fix is working. I already built the release binary, so I should run the reproduction test again.
Assistant
The issue persists. Let me trace through the code more carefully to understand what's happening. Let me check how the HTML template file's member accesses are extracted and whether they're being properly collected.
Assistant
Let me investigate how HTML template files are parsed and whether their member accesses are being collected. The issue might be that the HTML file isn't being processed correctly.
Assistant
The HTML file is being extracted and processed. Let me investigate how the member accesses are collected from HTML files. The key is to understand how the Angular template scanner is invoked for external HTML files.
Assistant
Let me continue investigating how HTML template files are processed and their member accesses collected.
Assistant
The HTML file parsing path is at line 72-73, calling
parse_html_to_module_with_complexity. Let me look at that function to see if Angular template refs are collected for HTML files.Assistant
Looking at the code, I can see that:
- HTML files ARE collecting Angular template refs (line 152 in
html.rs) - The refs are converted to member accesses with
ANGULAR_TPL_SENTINELfor identifiers and the actual object name for chains - The analysis code should connect these through
instance_bindings
Let me verify that my fix is actually extracting the instance binding correctly by running the test I added:
- HTML files ARE collecting Angular template refs (line 152 in
Assistant
Good, the extract test passes, confirming my fix adds the instance binding. But the reproduction case still fails. Let me trace through the analysis code more carefully to understand why the binding isn't being used to credit the member access.
Looking at the code in
unused_members.rsaround line 1502-1540:angular_tpl_chain_accessescollects member accesses from files that have Angular template refs- For each component file, it gets
component_bindingsfromclass_heritage - For each import, it looks up the chains in
angular_tpl_chain_accesses - For each chain, it resolves the object to a type via
component_bindings - It then looks up the export key via
local_to_export_keysand credits the member
The key issue might be in step 3 -
angular_tpl_chain_accesses.get(&target_id)might not find the template file because the template file might not be in the imports correctly.Let me check how the HTML template file is connected to its component:
Assistant
The template is imported as a side-effect from the component. Let me check if
all_resolved_importsincludes side-effect imports. If not, the template file won't be found in the loop.Assistant
I see -
all_resolved_importsreturns all imports including side-effect imports. The HTML template should be in there as a side-effect import. Let me verify that the template file is being resolved and that the chains are being found.Let me look at the logic flow more carefully. In the code at line 1502-1540:
- For each resolved module (component file)
- Get
class_heritagefromclass_heritage_by_file - Build
component_bindingsfrominstance_bindings - For each import (including the HTML template as side-effect)
- Get
target_id(the file ID of the HTML template) - Look up
angular_tpl_chain_accesses.get(&target_id)to find the chains
Wait, I think I see the issue now! Looking at line 1526:
Assistant
The existing test fixture uses constructor injection, not
inject(). This confirms the issue - the fix I made should handle theinject()case. Let me verify my fix is correct by checking the code path more carefully.Looking at the code flow:
extract_class_instance_bindingsextracts bindings from class properties- For
inject(Type)calls, it should add(property_name, Type)to the bindings - The analysis then uses these bindings to resolve template references
Let me check if the issue is that the analysis code is not finding the bindings correctly. Let me look at how
class_heritage_by_fileis built:Assistant
The
class_heritage_by_fileis built fromresolved_modules, and each module has aclass_heritagefield. My fix adds the inject binding toinstance_bindingswhich is part ofclass_heritage.Let me now verify that the issue is indeed resolved by creating a more comprehensive test. But first, let me make sure the test I added earlier is actually testing the right thing and passes:
Assistant
Looking at the code, I think the issue might be in how
local_to_export_keysis built. Let me check the full implementation of this function:Assistant
I see -
local_to_export_keysmaps local names (import aliases) to export keys. So if the component has:import { ExampleService } from './example.service';Then
local_to_export_keyswill have"ExampleService"mapped to the export key ofExampleServicein the service file.And
component_bindingsshould map"exampleService"to"ExampleService"(the type name).Let me verify the full flow:
- Template has:
exampleService.onValueChange(...) angular_tpl_chain_accessescollects:("exampleService", "onValueChange")for the HTML file- Component imports HTML file as side effect
component_bindingshas:("exampleService", "ExampleService")local_to_export_keyshas:("ExampleService", [ExportKey for ExampleService])- The code looks up
"exampleService"incomponent_bindings-> gets"ExampleService" - Then looks up
"ExampleService"inlocal_to_export_keys-> gets the export key
- Template has:
Assistant
Now I see a potential issue. The reproduction case uses:
readonly exampleService = inject(ExampleService);The condition checks for
Expression::Identifier(callee)where the callee isinject. This should match.But wait, the issue says the reproduction is failing. Let me run the reproduction again and also check if maybe the build didn't pick up my changes:
Assistant
The build shows "Finished" immediately, which suggests no recompilation happened. But I know my changes are there because the unit test passes. Let me force a clean rebuild:
Assistant
The build completed successfully after touching the file. Now let me run the reproduction test to see if the fix is working:
Assistant
The issue persists. Let me investigate more deeply. I suspect the problem might be related to how side-effect imports (like the HTML template) are handled in the analysis code. Let me trace through the logic more carefully.
Assistant
Assistant
The user is reminding me that I need to use proper tool calls. Let me continue investigating the issue by checking the code.
Assistant
Assistant
Good, I can see my changes are in the file. The unit test passes, confirming the binding is extracted. But the reproduction case still fails. Let me create a test fixture to debug this issue more systematically.
Assistant
The user sent an empty message, which means I should continue with my work. I was in the middle of creating a test fixture to debug the issue. Let me continue creating the test files for the fixture.
Assistant
The user sent an empty message, which means I should continue with my work. I was creating a test fixture to debug the issue. Now I need to run fallow on this fixture to see if the issue is reproducible and understand what's happening.
Assistant
The user sent an empty message again. I need to continue my work. The command failed because I used the wrong flag. Let me check the correct way to specify entry points for fallow.
Assistant
Excellent! The fix is working! Looking at the output, only
ExampleService.unusedMethodis reported as unused (which is correct - it's genuinely unused), whileExampleService.onValueChangeis NOT reported because it's correctly recognized as being used in the template!Let me verify this also works for the original reproduction case:
Assistant
Interesting! The new fixture I created works correctly (only
unusedMethodis reported as unused, whileonValueChangeis correctly recognized as used). But the original reproduction case still fails. Let me investigate the difference between the two.Assistant
Let me clear the cache in the repro directory and try again:
Assistant
The issue was a stale cache! After clearing the cache, the reproduction case now works correctly - no issues are found because
onValueChangeis correctly recognized as being used in the template.Now let me run the existing tests to make sure my fix doesn't break anything:
Assistant
All 1682 tests in fallow-extract pass! Now let me run the core tests to ensure the fix doesn't break anything:
Assistant
The user is showing me that all 641 tests in fallow-core passed. The fix is working correctly. Now let me clean up the test files I created and verify the final state of my changes.
Assistant
Let me verify the changes I made and clean up any test fixtures that shouldn't be submitted:
Assistant
Let me clean up the temporary test files and verify my final changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.