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:tsreadonly 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:json{ "name": "fallow-angular-template-repro", "version": "1.0.0", "private": true, "dependencies": { "@angular/core": "^20.0.0" } } -
Create
.fallowrc.json:json
-
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 first explore the repository structure to understand how the codebase is organized, particularly the Angular plugin.
Assistant
I need to explore the repository structure more systematically to understand the codebase and find the Angular plugin code.
Assistant
This is a Rust project (has Cargo.toml, crates directory). Let me explore the crates directory to find the Angular plugin.
Assistant
Let me search for Angular-related files in the crates directory.
Assistant
Let me look at the Angular plugin file and the related template handling code:
Assistant
I need to properly open the file without the "file" parameter name
Assistant
Let me look at the SFC template Angular code and the unused_members analysis:
Assistant
Now let me look at the
unused_members.rsfile, specifically how it handles Angular template references and bridges them to component class members:Assistant
This file is quite long. Let me search for the specific code that handles the Angular template references and component property type resolution:
Assistant
No "inject" found in unused_members.rs. Let me search for the Angular template sentinel handling:
Assistant
Let me look at those specific sections:
Assistant
I can see the key logic now. The code uses
component_bindingswhich is built fromclass_heritage→instance_bindings. Let me continue reading and then find whereinstance_bindingsare populated:Assistant
Now let me find where
instance_bindingsis populated:Assistant
Now let me look at the
extract_class_instance_bindingsfunction in helpers.rs - this is likely where the fix needs to be made:Assistant
I found the key function
extract_class_instance_bindings. Looking at the code forPropertyDefinitionhandling (around line 672-686):- First, it checks for
type_annotation- if there's an explicit type annotation, it extracts the type name and adds the binding. ✅ This handles typedinject(). - Then it checks for
new Expression- if the property is initialized withnew SomeClass(), it adds the binding. ✅ This handlesnewinitializers. - But it doesn't handle the case where the property is initialized with
inject(SomeClass)without a type annotation. ❌ This is the bug!
The fix should add a case that detects
inject(ClassName)call expressions in property initializers and extracts the class name from the first argument.Let me also check what the
injectfunction looks like in the Angular context:- First, it checks for
Assistant
Good, no existing
injecthandling. Let me look more carefully at the property definition handling section:Assistant
Now I understand the code. I need to add a case after the
newexpression handling that also detectsinject(ClassName)call expressions. Let me look at the test file to understand the expected behavior:Assistant
Let me now look at the existing Angular template fixture to see how it tests the DI-injected members:
Assistant
Command sequence (each separated by ||):
- Find and show all .ts files in the fixture
- Show the component file
- Show the service file
Assistant
I see - the existing test uses constructor injection which works. Let me first create a reproduction to confirm the bug, then implement the fix.
Let me first look at the visitor tests to understand the test patterns:
Assistant
Now I understand the codebase structure. Let me create the reproduction test case first, then implement the fix. Let me start by creating the reproduction files:
Assistant
Command was successfully executed. Now I need to continue creating the test fixture files. I'll create the example service file next.
Assistant
Now let me build the project and run the test to confirm the bug:
Assistant
Now let me run the analysis against the test fixture to reproduce the bug:
Assistant
I've confirmed the bug.
onValueChangeis incorrectly reported as unused (it's actually used in the template), andunusedMethodis correctly reported as unused. The issue is thatonValueChangeshould NOT be reported.Now let me implement the fix. The issue is in
extract_class_instance_bindingsin/fallow/crates/extract/src/visitor/helpers.rs. I need to add a case that detectsinject(ClassName)call expressions.Let me look at the relevant code again more carefully:
Assistant
Now I need to add a check for
inject(ClassName)call expressions. The pattern is:prop.valueisSome(expr)whereexpris aCallExpression- The callee is an
Identifierwith name"inject" - The first argument is an
Identifier(the class being injected)
Let me look at the imports at the top of helpers.rs:
Assistant
Command was successfully executed.
<tool_call> <function=bash_terminal> <parameter=command> sed -n '670,695p' /fallow/crates/extract/src/visitor/helpers.rs </tool_call>
Assistant
The previous command worked but I'm not sure what it did. Let me continue with my approach - I need to implement the fix in helpers.rs. Let me view the current state of the file.
Assistant
Now I can see the full code. I need to modify the
extract_class_instance_bindingsfunction to also handleinject(ClassName)call expressions. Let me make the edit:Assistant
Now I'll add the fix. I need to insert code after the
NewExpressioncheck (after line 685) that handlesinject(ClassName)call expressions.Assistant
I need to add handling for
inject(ClassName)call expressions after thenewexpression check. I'll add a new condition that checks if the property value is a call expression with callee "inject" and the first argument is an identifier.Assistant
Let me verify that the edit was applied correctly by checking the modified section of the file:
Assistant
The edit was applied correctly. Now let me rebuild and test to verify the fix works:
Assistant
The build succeeded. Now I need to test the fix by running the analysis against the test fixture I created earlier. Let me verify that the fix works correctly.
Assistant
The fix didn't work - still showing the same false positive. Let me debug this. First, let me check if the binary was actually updated and if the code change is correct:
Assistant
I see - the fix didn't work. Let me investigate further by checking if the template file is being resolved as an import from the component file. But first, let me verify the instance bindings are being extracted correctly:
Assistant
Let me find and run the existing instance bindings tests:
Assistant
All existing instance binding tests pass. Now let me write a test to verify that the
inject()pattern works correctly. Let me first check the existing test structure:Assistant
Let me look at the parse function in the tests module to understand how to write a test for the
inject()pattern. Then I'll add a test for it.Assistant
The
parsefunction is not found in tests.rs directly. Let me look at the imports in tests.rs to see whereparsecomes from.Assistant
I see. The
parsefunction comes fromcrate::tests::parse_ts. Let me now add a test for theinject()pattern to verify my fix works correctly. First, let me find the existing tests for instance bindings and add a new test after them.Assistant
Let me find where the test for new expression bindings is so I can add a similar test for the inject() pattern nearby.
Assistant
Let me look at the test around line 1030 which seems to test new expression in a class property:
Assistant
Now I understand the test structure better. Let me add a test for the
inject()pattern to verify my fix works. I'll add a test that checks that the instance binding is correctly extracted when a property is initialized withinject(ServiceClass).Assistant
Now let me add a test for the
inject()pattern. I'll add it after the existing instance binding tests. Let me first find a good place to add the test:Assistant
Now I need to add a test for the
inject()pattern. Let me insert a test after theexported_instance_binding_is_recordedtest. But first, let me understand why my fix isn't working. Let me check the test fixture more carefully and trace through what's happening.Assistant
Let me add a test for the
inject()pattern to verify the instance binding extraction is working correctly.Assistant
Let me add a unit test for the
inject()instance binding extraction to verify my fix is working correctly. I'll add it in the tests.rs file.Assistant
Let me add a test case for the
inject()pattern. I'll add it to the tests file. First, let me find the end of the instance binding tests section:Assistant
Let me add a test for the
inject()pattern in the instance bindings section. I'll insert a test after thegeneric_typed_property_resolved_via_constrainttest (around line 3315):Assistant
Now I'll add a test for the
inject()pattern. Let me insert it after line 3320 (after the closing brace ofgeneric_typed_property_resolved_via_constraint):Assistant
Let me add this test to the tests.rs file after line 3320.
Assistant
I see there's a syntax error in the test file - there's an extra closing brace
}on line 3347 that shouldn't be there. Let me fix this.Assistant
I see there's an extra closing brace
}on line 3347. Let me remove it.Assistant
Let me verify the fix and run the test.
Assistant
There's still an extra closing brace on line 3347 (
}). Let me remove it.Assistant
Let me verify the fix and run the test.
Assistant
I see there's still an extra
}on line 3346 and the#[test]attribute is missing. Let me fix this properly.Assistant
Good - the extra
}was removed. But now I need to add#[test]attribute beforefn dotted_bound_whole_object_preserves_suffix(). Let me do that.Assistant
The user hasn't said anything new - this is just the environment responding to my previous command. Let me verify the test file is now correct and run the tests.
Assistant
The file got messed up. The
#[test]was inserted in the wrong place and the closing brace}is now misplaced. Let me restore the file from git and redo the edit more carefully.Assistant
Good, the file is restored. Now let me add the test more carefully using the edit command:
Assistant
Now let me insert the test properly using sed to replace the blank line after the closing brace:
Assistant
The user hasn't said anything new - this is just the environment responding to my previous command. The sed command I used was quite complex and likely had issues with escaping. Let me check if the edit was applied correctly by examining the test file.
Assistant
The test was added successfully. Now let me run the test to see if the
inject()pattern is being detected correctly.Assistant
The unit test passes, which confirms the instance binding extraction is working. Now let me rebuild the release binary and test the full fixture to see if the issue is resolved.
Assistant
Interesting - it says "Finished" without recompiling. Let me force a rebuild:
Assistant
Good, the build is complete. Now let me test the fixture again to see if the fix works.
Assistant
Let me trace through the code more carefully. The unit test for instance bindings passes, but the full analysis still reports the false positive. Let me check if there's another step in the analysis pipeline that's failing.
Assistant
The existing Angular template tests pass, confirming the infrastructure works for constructor injection. Let me now investigate why my fix isn't propagating through the full analysis pipeline. Let me add some debug output to understand what's happening.
Assistant
The user is asking me to submit my changes. Let me check the current state and then submit.
Assistant
Looking at my changes, I've made the core fix but the integration test is still showing the false positive. Let me investigate further to make sure my fix is working end-to-end.
Assistant
There's an existing test
member_detection::angular_inject_fields_credit_service_member_usagethat seems related to my fix. Let me check what it tests.Assistant
Let me look at this existing test and its fixture to understand how it works.
Assistant
Let me look at the existing fixture to understand what pattern it tests.
Assistant
The user hasn't said anything new - this is just the environment responding to my previous command. I was examining the existing
angular-inject-class-membersfixture to understand the pattern it tests. Let me continue examining the fixture files to understand the difference between this working case and the failing case reported in the issue.Assistant
Now I understand the difference. The existing test uses
inject()inside the same class and accesses the service throughthis.inner.aaa. But the reported issue is about external template references where the service method is called from an HTML template file.Let me examine how the template accesses flow through the analysis pipeline.
Assistant
Let me continue investigating why the fix isn't propagating through the full pipeline. I need to check if the Angular template analysis is finding the component's instance bindings.
Assistant
The user hasn't said anything new - this is just the environment showing me the code. I need to understand the flow better. Let me look at how Angular templates are connected to their component files in the graph.
Assistant
Let me trace through the issue more carefully by checking how
class_heritage_by_fileis populated.Assistant
I see - the
class_heritage_by_fileis populated frommodule.class_heritage. Let me verify that my fix is actually being used by checking if the component's instance bindings are being extracted.Assistant
I need to investigate why the fix isn't working end-to-end. Let me first verify that my change didn't break any existing tests, and then trace through the issue more carefully.
Assistant
All 1682 tests pass. Now let me trace through the issue more carefully. I need to understand where in the pipeline the
inject()binding is being missed when connecting the template reference to the service method.Assistant
The issue is that when the template references
exampleService.onValueChange(), the analysis needs to:- Find the template file and extract the member access chain (
exampleService.onValueChange) - Link the template to its component (the
.component.tsfile) - Look at the component's
instance_bindingsto find thatexampleServicemaps toExampleService - Then credit
ExampleService.onValueChangeas used
The problem might be that the component bindings are looked up from the wrong file. Let me trace through the code at line 1502-1540 more carefully.
Looking at the code:
angular_tpl_chain_accessesis keyed by of the template file
- Find the template file and extract the member access chain (
Assistant
...
Assistant
Now I need to understand how the Angular template URL becomes an import. Let me check the extract code.
Assistant
Let me trace through the code path more carefully to understand why the fix isn't working end-to-end.
Assistant
... )
<tool_call> <function=bash_terminal> <parameter=command> cd /fallow && grep -rn "has_angular_component_template_url" crates/extract/src/ </tool_call>
Assistant
The user is telling me I need to make a function call. Let me investigate why the fix isn't working end-to-end.
Assistant
I need to understand how Angular template member accesses are stored. Let me check the Angular template extraction code to see if the template produces the right kind of member accesses.
Assistant
The
ANGULAR_TPL_SENTINELis defined in the Angular template scanner. Let me check where this sentinel is actually used to createMemberAccessentries. I need to trace how the template refs are converted into member accesses that get stored in the resolved module.Assistant
Let me examine how the HTML template parser handles member access chains. The issue is about external templates (
templateUrl), so I need to check thehtml.rsfile.Assistant
I need to trace through why my fix isn't working. The HTML template extracts member accesses like
{object: "exampleService", member: "onValueChange"}. This should be linked to the component'sinstance_bindingswhich mapsexampleService→ExampleService. Let me verify the fix is being applied correctly.Assistant
Let me force a clean rebuild to ensure the latest changes are picked up:
Assistant
Let me check if my changes are still in the file and force a rebuild:
Assistant
Good, my changes are still in place. Let me touch the file and rebuild:
Assistant
Let me test again with the rebuilt binary.
Assistant
Let me investigate further by checking how
build_local_to_export_keysworks and trace through the logic more carefully.Assistant
I need to trace through the code to understand why my fix isn't working end-to-end. Let me examine how the template reference flows through the analysis.
Assistant
I think I understand the issue now. Let me check how
class_heritageis populated - maybe it requires certain conditions to be met for a class to have its heritage recorded.Assistant
Wait, I see the condition now at line 436:
rustif !already_has_heritage && (local_class.super_class.is_some() || !local_class.implemented_interfaces.is_empty() || !local_class.instance_bindings.is_empty())This means that
class_heritageis only pushed if the class has instance bindings. So my fix should work because theinject()pattern adds an instance binding, which triggers this condition.But wait - the condition checks
local_class.instance_bindings.is_empty(). Let me verify that my fix is actually populating the instance bindings correctly by looking at therecord_exported_instance_bindingsfunction and how it's called.Let me trace through where
class_heritageis built. Looking at line 436, the condition!local_class.instance_bindings.is_empty()should be true for theExampleComponentclass with my fix. But maybe the issue is that the class isn't exported?Let me check the component file:
Assistant
Let me check if the template file is being resolved correctly by examining the graph resolution:
Assistant
... Let me continue investigating the issue. I need to understand how the template file is resolved and connected to the component file in the graph. The issue is that the template's member accesses (like
exampleService.onValueChange) need to be linked to the component's instance bindings.Let me check how the resolution works for the template URL.
Assistant
Looking at this more carefully, I need to understand how
class_heritageflows from extraction through to analysis. Let me check the graph module structure.Assistant
No results from graph. Let me check where
class_heritageis stored in the graph modules:Assistant
Let me examine the code path more carefully to understand why the fix isn't working:
Assistant
I see the issue now. Let me trace through the code path more carefully to understand why my fix isn't working end-to-end. The unit test passes, so the instance binding extraction works. But there must be something else in the pipeline that's failing.
Assistant
Assistant
Let me verify the template file content and then trace through the issue more carefully:
Assistant
I need to trace through the issue more carefully. Let me check if the component class is being visited correctly and if the
class_heritageis being populated.Assistant
Let me examine how
class_heritageis populated in the visitor - specifically the condition that gates whether heritage is recorded:Assistant
I see the
class_heritageis recorded wheninstance_bindingsis non-empty. My fix should populate this. But let me check if there's something else gating the recording. Let me look at howlocal_classis built and whenrecord_exported_classis called:Assistant
The previous command returned empty. Let me search for where
record_exported_classor similar functions are defined and called in the visitor module.Assistant
The user is waiting for me to respond. I need to continue investigating why my fix isn't working. The previous search didn't find "record_exported_class" - let me search for the function that records class heritage differently.
Assistant
Let me examine the
record_local_class_exportfunction and trace through how instance bindings flow:Assistant
Let me trace through how the class heritage flows from extraction to analysis. I need to understand where the
record_local_class_exportis called and howinstance_bindingsgets populated.The key insight is:
extract_class_instance_bindings(class)is called to extract bindingsrecord_local_class_export(name, members, super_class, implemented_interfaces, instance_bindings)is called to record the class- Later,
class_heritageis built fromlocal_class_exports
Let me trace where
record_local_class_exportis called from and how the flow works.Assistant
Good, I can see that
extract_class_instance_bindings(class)is called and passed torecord_local_class_export. Now let me trace howclass_heritageis built fromlocal_class_exports:Assistant
I need to continue investigating the issue. Let me trace through how
class_heritageis built fromlocal_class_exportsby looking at theenrich_local_class_exportsfunction.Assistant
Let me run the existing Angular template tests to make sure the infrastructure works:
Assistant
Let me trace through how
resolved_modulesis populated in the analysis:Assistant
Let me trace how
class_heritageflows from the extracted module info to the analysis:Assistant
The previous command did execute successfully and showed that
class_heritageis defined in the types crate. Let me continue investigating the issue by looking at how the analysis receives theclass_heritagedata.Assistant
Let me check where the Angular component metadata extraction happens in the visitor:
Assistant
Let me check if the test fixture's HTML template is actually being discovered and analyzed by fallow:
Assistant
Let me try a different approach - let me create a targeted test that mirrors the working test but uses the untyped
inject()pattern:Assistant
The build seems to have cached the previous result. Let me force a rebuild by touching the helpers.rs file again and rebuilding.
Assistant
Good, the build completed. Let me now test the fix with the freshly rebuilt binary:
Assistant
Let me compare the working fixture with my test fixture to understand the difference:
Assistant
Let me check if there's a difference in how the fixtures are set up. The working fixture has more Angular dependencies. Let me also check if there's a node_modules directory or if npm install was run.
Assistant
Let me investigate why the fix isn't working end-to-end by checking how the Angular template analysis connects to the component's instance bindings:
Assistant
Let me check what the Angular template scanner extracts for my test template:
Assistant
Let me trace through the template parsing to understand how member accesses are extracted:
Assistant
Let me look at
collect_statement_refsto understand how member accesses are extracted:Assistant
Let me look at how
collect_statement_refsandcollect_expression_refswork to understand how member accesses are extracted from the template.Assistant
Let me investigate further by testing the constructor injection pattern on my fixture to confirm the pipeline works:
Assistant
The constructor injection pattern works!
onValueChangeis correctly NOT reported as unused. Now let me test with typedinject():Assistant
The typed
inject()pattern works too! Now let me test the untypedinject()pattern (the failing case):Assistant
The fix is working now! The untyped
inject()pattern correctly creditsonValueChangeas used, and onlyunusedMethodis reported as unused (which is correct - it's genuinely unused).Let me verify all four patterns work correctly:
Assistant
All four patterns now work correctly - only
unusedMethodis reported as unused, andonValueChangeis correctly credited as used. The fix is working!Let me now restore the original test fixture and run the existing tests to ensure nothing is broken:
Assistant
Let me restore the test fixture and run the existing tests to make sure nothing is broken.
Assistant
All 1682 extract tests pass. Let me also run the core tests to verify the full analysis pipeline:
Assistant
All 641 core tests pass. Let me verify my changes are correct and complete:
Assistant
Let me verify my changes are complete by reviewing the diff and ensuring all tests pass before submitting.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.