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 understand the issue:
- Fallow is a tool that detects dead code (unused code).
- When using Angular, if a component property is initialized with
inject(Service)without an explicit type annotation, the service methods referenced in the HTML template are reported as unused. - The fix should be in the fallow codebase itself.
Let me start by exploring the repository structure.
Assistant
This is a Rust project. Let me explore the structure more.
Assistant
Let me search for Angular-related code and the
injectfunction handlingAssistant
Let me look at the Angular plugin and the integration test:
Assistant
The Angular plugin is more about entry points. The issue is about template member resolution for dead code detection. Let me search for how Angular templates are resolved.
Assistant
Let me look at the Angular template members integration test and the unused members analysis:
Assistant
Let me look at the core unused members analysis and how it handles Angular templates
Assistant
Let me search for the key parts related to Angular template resolution and how inject() is handled.
Assistant
No results for "inject" in unused_members.rs. Let me search more broadly.
Assistant
Now let me look at the key files. First, the
extract_angular_inject_targetfunctionAssistant
Let me look at the code around lines 1637 and 1886 in visit_impl.rs to understand the handling.
Assistant
Now let me look at line 1886 where this function is called.
Assistant
Let me look at the template usage resolution and also find where
this.Xbinding targets are used to resolve templateAssistant
Let me look at the extract module and how Angular templates are processed:
Assistant
Let me look at how external Angular templates are extracted - searching for "external" or "html" in the extract crate
Assistant
Let me look at the parse and html files to understand external template processing
Assistant
Let me look at the property definition handling in visit_impl.rs, especially around the
injectand binding_target_names:Assistant
Let me search for
record_typed_bindingandbinding_target_namesdefinitionsAssistant
Let me look at the
record_typed_bindingfunction and the structure definition for binding_target_namesAssistant
Let me look at how external templates are scanned and resolved:
Assistant
Now let me look at the
sfc_template::angularmodule:Assistant
Let me look at the sfc.rs file:
Assistant
Let me find and look at the sfc_template module:
Assistant
Let me look at the angular template scanner:
Assistant
Let me look at how template member accesses are resolved through binding targets in the unused_members analysis:
Assistant
Let me look at the relevant section in unused_members.rs around lines 1502-156
Assistant
Now let me search for
instance_bindingsto understand how they're populated:Assistant
Let me look at
extract_class_instance_bindings:Assistant
Let me see the rest of this
Assistant
Now I see the issue! The
extract_class_instance_bindingsfunction inhelpers.rshandles type annotations, constructor params, andnewexpressions but NOTinject()calls. Let me verify by checking the function more carefully and looking at how the visitor handles injectAssistant
Let me look at the integration test for angular inject fields and the test fixtures
Assistant
Let me look at the test fixtures:
Assistant
Let me look at these fixture files:
Assistant
Let me look at the test fixtures for angular-template-inherited-members:
Assistant
Let me look at how
extract_class_instance_bindingsis called in declarations.rs:Assistant
Let me look at how
binding_target_namesflows through the system and check thepropagate_accesses_through_typed_instance_bindingsfunction:Assistant
Let me continue reading:
Assistant
Let me check the
is_builtin_constructorfunction and understand hownewexpressions are handled versus how I should handleinject():Assistant
Let me check the imports in helpers.rs:
Assistant
Let me look at the test for
angular_inject_field_maps_this_field_member_access:Assistant
Let me check what functions are available in helpers.rs:
Assistant
Let me check if
type_name_rootexists:Assistant
Let me look at
extract_type_reference_name:Assistant
Now I have a clear understanding. The issue is in
extract_class_instance_bindingsinhelpers.rs. It handles:- Type annotations on properties
- Constructor parameter injection
newexpressions
But it does NOT handle
inject()calls. I need to add that. Let me create a reproduction script first, then fix it.Let me first set up the reproduction and verify the bug:
Assistant
Let me first build the project and also look at the existing tests to make sure I understand what needs to change:
Assistant
Good, it builds. Let me create the reproduction described in the issue:
Assistant
Let me create the reproduction files and run the test:
Assistant
Now let me run fallow to reproduce the issue:
Assistant
I've successfully reproduced the issue. Now let me verify the control cases work (constructor injection and typed inject):
Assistant
Now let me test the typed inject case:
Assistant
Both control cases work. Now let me implement the fix. I need to add
inject()handling inextract_class_instance_bindings:Assistant
I need to change directories back to /fallow first.
Assistant
Now let me add the
inject()handling. I'll add code after theNewExpressioncheck:Assistant
Let me try a different approach with the edit command:
Assistant
Let me try
replace:Assistant
Let me use a Python script to make the edit:
Assistant
Let me use a script file to avoid bash escape issues:
Assistant
Let me verify the change:
Assistant
Now let me build and test:
Assistant
Build succeeded. Now let me run the reproduction test:
Assistant
The fix works! Now let me run the existing tests that are related to this functionality:
Assistant
Let me run the integration tests for angular template members and member detection:
Assistant
Now let me run the injected dependency and angular inject tests:
Assistant
Let me use a different filter approach:
Assistant
The filter syntax might not be right. Let me try a different approach:
Assistant
Let me also run the broader set of related tests:
Assistant
All member detection tests pass. Let me also run the visitor tests related to instance bindings:
Assistant
Let me also run the complete extract test suite to make sure nothing is broken:
Assistant
All 1681 tests pass. Let me also run the core tests related to unused members:
Assistant
Let me verify the fix also works for
inject<Type>(...)with type arguments but no property type annotation:Assistant
Actually, that ran against the fallow repo itself. Let me re-run the test properly:
Assistant
Let me run the binary from the /tmp directory:
Assistant
Let me verify the original broken case once more:
Assistant
Let me also verify that genuinely unused members are still reported (no false negatives):
Assistant
Genuinely unused members are correctly reported. Let me run all the tests I can to make sure nothing is broken:
Assistant
All 641 integration tests pass. Let me clean up the temporary files:
Assistant
Let me verify the final state of my changes:
Assistant
The changes look correct. Let me now go through the checklist:
CHECKLIST:
-
If an error was reported in the issue description, I have successfully reproduced it. ✅
- I reproduced the false positive with
readonly exampleService = inject(ExampleService);reportingExampleService.onValueChangeas unused.
- I reproduced the false positive with
-
If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅
- After the fix, the same code reports
✓ No issues found.
- After the fix, the same code reports
-
I have thought about edge cases and made sure my fix handles them as well. ✅
-
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.