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
Let me analyze this issue. The problem is that
fallow dead-codereports a service method as unused when it's referenced in an Angular HTML template through a component property that's initialized withinject()without an explicit type annotation.Let me start by exploring the repository structure to understand how the codebase is organized, particularly the Angular plugin.
Assistant
Let me look at the Angular-related test fixtures and the unused_members analysis code:
Assistant
This is a different issue (about
injectin services). Let me look at the template-related fixtures:Assistant
Now let me look at the
unused_members.rsfile which likely handles the logic for detecting unused class members:Assistant
Let me look at the area around
angular_tpl_refsandangular_tpl_chain_accessesmore closely - these seem to be the key parts for handling Angular template references:Assistant
I need to use the correct format for opening files with line numbers.
Assistant
This is really interesting. I can see the logic for Angular template chain accesses. The key is
component_bindingswhich comes fromclass_heritageandinstance_bindings. Let me search for howinstance_bindingsare populated:Assistant
Let me look at where
instance_bindingsis populated. Let me search for theClassHeritagestruct definition:Assistant
I should escape the special characters properly or use a different search approach.
Assistant
Let me search for the
ClassHeritagestruct definition more broadly:Assistant
Let me look at the
ClassHeritageInfostruct definition:Assistant
Now I can see that
instance_bindingsis aVec<(String, String)>that maps local property names to type names. This is used to resolve member-access chains in external templates. Let me look at where this is populated in the extraction visitor:Assistant
Let me look at the
extract_class_instance_bindingsfunction in helpers.rs, which is the key function that extracts the instance bindings from a class:Assistant
Now I can see the issue clearly! In
extract_class_instance_bindings, the function handles:- Constructor parameters with type annotations (line 626-649)
- Getter methods with return type annotations (line 650-668)
- Property definitions with:
- Explicit type annotations (line 681-688)
new Expressioninitializers (line 689-694)
But it does NOT handle the case of
inject(ClassName)as an initializer expression without a type annotation. Let me look at the exact code:Assistant
I can see the problem. The current code handles
new ClassName()but notinject(ClassName). I need to add support for CallExpression where the callee isinjectand the first argument is the class name.Let me first reproduce the issue to confirm:
Assistant
Now I need to create the HTML template file and then run the fallow tool to reproduce the issue.
Assistant
I need to build the project first. Let me check the build system.
Assistant
Let me try a debug build which is typically faster:
Assistant
Now let me run the fallow command on the reproduction case to confirm the issue:
Assistant
I've confirmed the issue. Now let me look at the relevant code more carefully. The fix needs to be in
extract_class_instance_bindingsin/fallow/crates/extract/src/visitor/helpers.rs. I need to add handling forinject(ClassName)call expressions.Let me look at what imports are already available in the helpers file:
Assistant
Now let me look at the exact code I need to modify. I'll look at the property definition handling part:
Assistant
Now I understand the structure. I need to add a case for
CallExpressionwhere the callee isinjectand the first argument is an identifier that represents a class. Let me look at how CallExpression is handled elsewhere in this file:Assistant
Good. Let me also check the
is_builtin_constructorfunction to understand how to exclude built-in functions:Assistant
Now I understand the pattern. Let me also check if there are any tests for
extract_class_instance_bindings:Assistant
I need to escape the special characters properly or use a different search approach.
<tool_call> <function=bash_terminal> <parameter=command> grep -n "extract_class_instance_bindings" /fallow/crates/extract/src/visitor/tests.rs 2>/dev/null || echo "Not found" </tool_call>
Assistant
I see there was an issue with the output - it seems to have printed "ERROR:" which was from a previous command, but my command actually ran fine. Let me look at the actual tests.
Assistant
Let me look at the existing tests for instance_bindings to understand the test patterns.
Assistant
Good, I can see how tests are structured. Now let me look at the tests around line 3245 and 3315 which also test instance_bindings to see more patterns:
Assistant
Now I have a clear understanding of the issue. The
extract_class_instance_bindingsfunction needs to handle the case where a property is initialized withinject(ClassName)- a CallExpression where the callee isinjectand the first argument is the class identifier.Let me implement the fix:
Assistant
Now I'll implement the fix. I need to add handling for
inject(ClassName)call expressions. The fix should be added after theNewExpressionhandling in thePropertyDefinitionbranch:Assistant
I need to add a case for
inject(ClassName)call expressions after theNewExpressionhandling. Let me edit the file:Assistant
I need to add handling for
inject(ClassName)call expressions. Let me edit the file:Assistant
Now I'll add the fix to handle
inject(ClassName)call expressions. I need to add a case for CallExpression after the NewExpression handling:Assistant
The user is pointing out that my function call had incorrect formatting. I need to properly format the bash command. Let me fix this and actually execute the command to make the edit.
Assistant
I need to add handling for
inject(ClassName)call expressions after line 685. Let me use sed to insert the new code.Assistant
The user is warning me about making tool calls incorrectly. Let me be careful with my next response and make sure I properly format any function calls. I need to verify that my sed command actually worked correctly.
Assistant
The sed command worked, but I need to check if
Argumentis imported in this file since I'm usingArgument::Expressionin my new code. Let me check the imports at the top of the file.Assistant
Good,
Argumentis already imported. Now let me build the project to verify the code compiles correctly.Assistant
The
Argument::Expressionvariant doesn't exist in this version of oxc_ast. The error suggests usingas_expression()method instead. Let me check how arguments are accessed elsewhere in the codebase.Assistant
I see! The pattern is to use
Argument::as_expression()method, notArgument::Expression. Let me also see how they match against identifiers from arguments:Assistant
I see!
Argument::Identifieris a valid variant. So I should useArgument::Identifierdirectly for the class name argument. Let me fix my code:Assistant
Now let me re-insert the corrected code after line 685 (after the
newexpression handling):Assistant
Now let me add the inject handling after line 685:
Assistant
the user is saying I didn't make a tool call. I need to verify my changes were applied correctly by viewing the file.
Assistant
The code looks correct. Now let me build the project to verify it compiles.
Assistant
The extract crate compiles successfully. Now let me build the full CLI and test the fix against the reproduction case.
Assistant
Now let me test the fix against the reproduction case.
Assistant
Hmm, the issue is still present. Let me investigate further. The fix I made should add the instance binding for
inject(ExampleService), but the template reference might not be getting resolved properly. Let me check if the instance binding is being extracted correctly first.Assistant
Let me look at how the Angular template chain accesses are resolved in more detail. The key is around line 1510 where
component_bindingsis built fromclass_heritage:Assistant
Let me investigate how
class_heritage_by_fileis populated and check if the Angular component's class heritage is being collected properly.Assistant
Let me understand how the Angular template references flow through the system. Let me look at how the HTML template is associated with the component file.
Assistant
The user is pointing out that my previous response didn't include a proper tool call. I need to continue investigating why my fix isn't working. Let me look at how Angular templates are resolved and how member accesses are extracted from them.
Assistant
The user is telling me my thinking was cut off. Let me continue investigating the issue. I've added code to handle
inject(ClassName)inextract_class_instance_bindings, but the fix isn't working yet. Let me trace through the flow more carefully.The issue is about how Angular template references are resolved to class members. The flow seems to be:
- HTML template extracts member accesses with
ANGULAR_TPL_SENTINELas the object - The analysis phase resolves these template references through component properties using
instance_bindings
Let me check if my fix is actually being triggered and if the instance binding is being extracted. I should also verify the test fixtures to see how this is supposed to work.
- HTML template extracts member accesses with
Assistant
The user is telling me my thinking was cut off. Let me continue investigating and look at how Angular template references are resolved to see why my fix isn't working.
The key is that when the HTML template is parsed, it extracts member accesses like
exampleService.onValueChangewithANGULAR_TPL_SENTINELas the object. Then in the analysis phase (unused_members.rs), these template references need to be resolved to actual class types using theinstance_bindingsfromclass_heritage.Let me check the existing test fixtures and see how they handle this, and also add some debug output to understand why my fix isn't working.
Assistant
Interesting! This test fixture uses
inject(UserService)without type annotations. Let me see if the tests pass for this fixture and what the expected output is. This might help me understand if my fix is correct or if there's something else going on.Let me also check the HTML template to see how the member accesses look.
Assistant
The user is pointing out that I had a thinking tag but didn't provide the actual tool call after it. Let me continue my investigation.
Assistant
The user is pointing out that my thinking was cut off. Let me continue investigating and complete my analysis.
I found that the template URL creates a side-effect import from the component to the HTML template file. Now I need to understand how the angular template chain accesses are resolved through the import graph.
Let me trace through the flow:
- Component file has a side-effect import of the HTML template (via templateUrl)
- The HTML template is parsed and creates member accesses
- In the analysis, the code looks at imports to find files with angular_tpl_chain_accesses
So the flow should be:
- Component imports service and has side-effect import of HTML template
- HTML template has member accesses like
exampleService.onValueChange - The code should find that the component has instance_bindings (with my fix)
- Then it should look at imports - but which imports?
Let me re-read the code at line 1520-1540 more carefully.
Assistant
Now I understand the flow:
- For each component file (
resolved), it getscomponent_bindingsfrom class_heritage (which includes my fix forinject()) - It iterates over all imports of the component file
- For each import target, it checks if that target has
angular_tpl_chain_accesses - If yes, it matches the object name from the template chain against
component_bindingsto get the type name - Then it uses
local_to_export_keysto find the export key for that type
The key insight:
local_to_export_keysis built from the component file (not the template file), and it maps local type names to export keys. So if the component importsExampleServiceand uses it locally asExampleService, the mapping should beExampleService -> ExportKey(service_file, "ExampleService").Wait, but the component_bindings would have
exampleService -> ExampleService(property name to type name). Andlocal_to_export_keysmaps type names to export keys.Let me check how
build_local_to_export_keysworks.- For each component file (
Assistant
Now I understand the flow better. Let me check if class_heritage is being populated correctly for Angular components. The issue might be that the component class doesn't have class_heritage recorded unless it has
instance_bindings, but there's a condition that gates when class_heritage is recorded.Assistant
Good! The condition at line 62-64 shows that class_heritage is only recorded if:
super_class.is_some()- class extends something!implemented_interfaces.is_empty()- class implements interfaces!instance_bindings.is_empty()- class has instance bindings
My fix should add instance bindings for
inject(ExampleService), so the class heritage should be recorded. But let me verify by checking if the Angular component decorator handling might be interfering.Let me also check if there's special handling for Angular components that might be relevant.
Assistant
The user is telling me that I need to include a tool call in my response. Let me continue investigating by looking at the
has_angular_class_decoratorfunction and understanding how Angular components are handled.Assistant
I need to continue investigating the issue. Let me check the
has_angular_class_decoratorfunction and understand how the Angular component template URLs are handled. I also need to check if my fix forinject()is being picked up correctly.Let me run the existing tests first to see if my changes break anything, and then I'll add some debugging to understand why the fix isn't working.
Assistant
Let me check if there are existing tests for the
inject()pattern that might help me understand why my fix isn't working:Assistant
I see there are existing tests for
inject()in the test file. Let me look at those tests to understand howinject()is already being handled:Assistant
The user is pointing out that I had a thinking tag but didn't provide the actual tool call after it. Let me continue investigating by looking at how
inject()is currently handled for member access resolution.Assistant
I see - there's already handling for
inject()that resolvesthis.inner.aaatoInnerService.aaawithin the class. But my fix is for instance_bindings which are used for template references. Let me find where the existing inject() handling is:Assistant
The user is telling me that I didn't include a tool call in my last response. I need to continue investigating. Let me look at the
extract_angular_inject_targetfunction and how it's used invisit_impl.rsto understand the existing inject() handling.Assistant
I need to make sure I include a proper tool call after my thinking tag. Let me continue investigating the issue by looking at how the existing inject() handling works and why my fix for instance_bindings might not be working.
Assistant
I see now! There are TWO different mechanisms for handling
inject():binding_target_namesin visit_impl.rs - for resolvingthis.xxx.member_accesswithin the same classinstance_bindingsin helpers.rs - for resolving template references
The key insight is that
extract_angular_inject_targetchecks ifinjectis from@angular/core, but my fix doesn't check this. Let me verify my fix is correct and run the existing tests.Assistant
All 1681 tests pass. Let me now test the reproduction case again to see if my fix works:
Assistant
My fix isn't working yet. Let me investigate further. I need to check if the instance bindings are being correctly extracted and if the resolution logic is working. Let me add a test to verify the extraction first.
Assistant
The grep command returned an error because the pattern wasn't found. Let me check if there are any tests for instance_bindings with inject pattern, and also verify that my fix is actually being triggered by looking at the extracted instance_bindings.
Assistant
The user is saying "Current open file must be specified". Let me check if there's an open file issue. Actually, looking back, I think the user is pointing out that I should have an open file to work with. Let me open the helpers.rs file and then continue my investigation.
Assistant
The user is asking me to continue. I was investigating why my fix for
inject()isn't working for Angular template references. Let me continue tracing the issue.The key question is: does the component file's imports include the HTML template file? If so, the analysis code should find the chain accesses in the template file.
Let me look at how template URLs create imports in the module graph.
Assistant
The user wants me to continue investigating. Let me look at how the template URL creates an import/asset reference in the code. I need to see lines around 3028 to understand how the template URL is processed.
Assistant
Now I understand the flow better. The template URL creates a side-effect import in the component file. Let me check if HTML templates are parsed and whether they're being associated with the correct module.
Assistant
Let me trace through the analysis code more carefully. I need to understand if the HTML template's chain accesses are being properly associated with the component's imports. Let me check the HTML parsing and how chain accesses work for external templates.
Assistant
Let me look at how Angular template references are collected to understand what member accesses are produced for chain accesses like
exampleService.onValueChange(...):Assistant
I see the issue now. My fix is in
extract_class_instance_bindingsinhelpers.rs, but I need to verify it's being called correctly. Let me also check if the Angular template chain access resolution is working properly. Let me write a simple test to debug this.Assistant
Let me continue investigating by checking if the instance bindings are actually being extracted for the
inject()pattern. I need to verify the fix is working correctly.Assistant
The user is asking me to continue my investigation. I was trying to create a test file to debug the issue, but I should instead write a proper test case within the existing test framework. Let me add a test case to verify that
inject()creates instance bindings for template reference resolution.Assistant
Let me look at this existing test to understand the pattern, then add a similar test for
inject():Assistant
The user wants me to continue. I was about to investigate why my fix for
inject()isn't working. Let me first check if there's a condition in the existing code that might be blocking my fix - specifically, I notice that the existingangular_inject_field_maps_this_field_member_accesstest checks thatthis.inner.aaamaps toInnerService.aaa, but that's done throughbinding_target_names, notinstance_bindings.Let me check if my fix is actually working by examining the extracted code more closely, and also verify that the instance_bindings extraction happens for Angular components with
templateUrl.Assistant
The user wants me to continue. I need to properly format my tool calls. Let me investigate whether the
newexpression pattern works for instance_bindings and compare it with myinject()fix.Assistant
The user seems to be experiencing timeout issues. Let me continue with my investigation. I need to verify that my fix is correct and check if there are any issues with how instance_bindings are being extracted for the
inject()pattern.Let me search for tests that verify instance_bindings for
newexpressions to compare with myinject()fix.Assistant
Let me continue investigating by looking at a simpler approach. I'll check if my fix is actually being hit by looking at the code path more carefully. The issue might be that the
extract_class_instance_bindingsfunction is called but my new condition isn't being satisfied.Assistant
Let me think about this more carefully. My fix adds instance_bindings for
inject(ClassName)patterns, but the issue might be elsewhere. Let me check if the extraction is working correctly by adding a unit test.Assistant
Assistant
The user is pointing out that my tool call had an error. Let me re-examine what happened. Looking at my tool call, it seems like the format was wrong. I used
bash_terminalbut the function name should be correct. Let me check if there's an issue with the function call format.Actually, looking more carefully at my tool call, I see I did use the correct format with
bash_terminalas the function name andcommandas the parameter. The error message says "No tool call was invoked" which suggests there was a parsing issue.Let me try again with the exact correct format.
Assistant
The
angular-template-complexityfixture passes with "No issues found" - which means my fix works for that case. Let me compare the two scenarios more carefully.In
angular-template-complexity, the services (FeatureFlagService, etc.) are defined locally in the same file as the component. In my reproduction case,ExampleServiceis imported from another file.Let me check if the
angular_tpl_chain_accessesresolution path handles imported services correctly:Assistant
The template is correctly structured. Let me trace through the angular template parsing to understand what member accesses are being produced:
Assistant
The user is pointing out timeout issues. Let me continue investigating the problem efficiently by checking if the issue is in the template parsing or in the resolution logic.
Assistant
Let me investigate the
collect_unresolved_refs_and_accessesfunction to understand how member accesses are extracted from templates, and trace through the resolution logic to find why imported services aren't being resolved correctly.Assistant
The user is waiting for me to continue. Let me look at the
collect_unresolved_refs_and_accessesfunction to understand how it extracts member accesses from Angular templates.Assistant
Let me investigate this more systematically by checking if there are tests for Angular template dead code resolution:
Assistant
The user is pointing out that my command failed. The grep command didn't find any matches because the pattern
testwasn't in the lines that containedangular,template, ortpl. Let me continue investigating by looking at the unused_members tests more carefully to understand how Angular template resolution is tested.Assistant
Let me continue investigating by looking at how the tests set up module graphs with Angular template scenarios. I need to understand the full flow from module extraction to analysis.
Assistant
Let me verify my fix is working correctly by testing the different patterns from the issue description. First, let me check if the typed
inject()pattern works (which the issue says should work):Assistant
The user wants me to continue investigating. Let me test the typed inject pattern to confirm it works.
Assistant
Good - the typed
inject()works as expected. Now let me test the untyped version with my fix:Assistant
The user wants me to continue investigating. I've restored the untyped inject pattern and now I need to test it again.
Assistant
Excellent! My fix is working! The untyped
inject()pattern now correctly resolves and shows "No issues found". Let me verify all the control patterns from the issue description work correctly:Assistant
Good, constructor injection works. Let me test the
newpattern:Assistant
All four patterns from the issue description now work correctly. Let me run the existing tests to make sure my fix doesn't break anything:
Assistant
All 1681 extract tests passed. Let me also run the core crate tests to make sure the unused_members analysis still works correctly:
Assistant
All 641 core tests passed. Now let me also run the end-to-end tests for the Angular fixtures to make sure everything works:
Assistant
The
cargo test angularfilter didn't match any test names. Let me check how the Angular test fixtures are tested in this repository:Assistant
I need to make sure I include a proper tool call after my thinking tag.
Assistant
The filter didn't match any tests. Let me try a broader search and run the Angular-related tests properly:
Assistant
The Angular tests are in the health_tests.rs file, but they're not being picked up by the filter. Let me run the health_tests specifically to verify my changes don't break them.
Assistant
The Angular template complexity test passes. Let me also run a few more Angular-related tests to make sure everything is working:
Assistant
The filter didn't match any tests with "health_angular". Let me run all the health tests to ensure they pass:
Assistant
All 45 health tests pass. Let me now test some edge cases to make sure my fix is robust:
Assistant
Edge case with inject options works. Let me test more edge cases:
Assistant
This is correct behavior! Private properties can't be accessed from Angular templates, so the service method should still be reported as unused. The existing code already skips private properties (line 666-667), which my fix respects.
Let me test the
readonlykeyword (which should work):Assistant
All edge cases work correctly. Let me also verify that my fix doesn't create false positives for non-Angular inject functions. Looking at the existing code, there's a test
non_angular_inject_function_does_not_map_field_member_accessthat verifies this. But my fix doesn't check ifinjectcomes from@angular/core. Let me check if this is a problem:Assistant
Looking at the code, I notice that my fix doesn't verify that
injectcomes from@angular/core. However, this is actually consistent with the existingnewexpression handling (line 680-685), which also doesn't check the import source. Thenewexpression just uses the class name directly without any verification of where it comes from.The key difference is:
- For
this.field.memberaccess within a class (handled invisit_impl.rs), there's a check thatinjectis from@angular/coreviaextract_angular_inject_target - For
instance_bindings(handled inhelpers.rs), thenewexpression pattern doesn't check import sources either
So my fix is consistent with the existing
newexpression handling. Theinstance_bindingsare used for template reference resolution, and if someone has a class withprop = inject(SomeClass), it's reasonable to assume it's Angular DI and bind it accordingly.Let me verify my changes are complete by looking at the git diff:
- For
Assistant
The git diff shows my change is minimal and focused. Let me verify once more that the fix works correctly by running the full test suite:
Assistant
All tests pass. Let me submit my changes now.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.