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 when an Angular component property is initialized with
inject()without an explicit type annotation, the fallow tool doesn't recognize that the property references a service class, so template references to methods on that service are incorrectly reported as unused.Let me start by exploring the repository structure to understand how the codebase is organized.
Assistant
Let me explore the structure more to understand the codebase, particularly looking for Angular-related code.
Assistant
Let me search for Angular-specific handling in the codebase.
Assistant
Let me explore the Angular plugin code since this is specifically about Angular template bindings and the
inject()pattern.Assistant
The Angular plugin is about detecting Angular projects and marking files as entry points, not about template resolution. The issue is about resolving template references to component properties. Let me look at the template usage and extract-related code.
Assistant
Let me look at the test fixtures for Angular templates to understand how the testing works.
Assistant
Let me explore the fixture that seems most relevant -
angular-template-inherited-members.Assistant
Now I need to explore the repository structure more carefully. Let me look at the test fixtures for angular-template-inherited-members to understand how they work and what patterns are already tested.
Assistant
Now I need to understand how fallow resolves template references to component properties. Let me look at how the extraction works for template bindings, particularly how it resolves property references to their types. The key is understanding how fallow links:
- Template references (e.g.,
exampleService.onValueChange($event.target.value)) - Component properties (e.g.,
exampleService) - Property types (e.g.,
ExampleService)
When a property has a typed declaration like
svc: ExampleService = ..., the type is clear. But when it'ssvc = inject(ExampleService), the type information comes from the argument toinject(), which fallow apparently isn't extracting properly.Let me look at the extraction code for handling
inject().- Template references (e.g.,
Assistant
Let me look at the visitor/declarations file in the extract crate to understand how properties are extracted and how types are resolved.
Assistant
Let me continue investigating. I need to understand how the extraction code handles
inject()calls and how template references are resolved. Let me look at the extraction visitor code.Assistant
Let me look at the helpers file to understand how
inject()is handled.Assistant
Let me look at the visitor/mod.rs to understand how class fields are extracted.
Assistant
Let me look at more of the visitor code to understand how class members are extracted and how
inject()is handled.Assistant
Let me continue exploring the visit_impl.rs file to find where
inject()calls are handled.Assistant
Let me look at the code around line 1637 and 1886 to understand how inject() is handled.
Assistant
Let me look at the area around line 1886 where
extract_angular_inject_targetis called.Assistant
Now I understand the injection handling code. Let me look at the unused_members analysis to see how it handles Angular template references.
Assistant
Let me continue reading the unused_members.rs to understand how template references are credited.
Assistant
Now I can see the structure. Let me look at the
build_typed_instance_binding_targetsfunction and the angular template reference handling code.Assistant
Let me continue exploring the unused_members.rs code for Angular template references:
Assistant
Now I need to understand how
extract_class_instance_bindingsworks and how the instance bindings are resolved. Let me look at that function.Assistant
Let me look at the
extract_class_instance_bindingsfunction to understand how it handles different patterns.Assistant
Now I understand the issue. The
extract_class_instance_bindingsfunction inhelpers.rshandles constructor parameters, typed properties, andnewexpressions, but it does NOT handleinject()calls without a type annotation.Let me check how
inject()is currently handled in the extraction:Assistant
Now I understand the issue. The
extract_class_instance_bindingsfunction inhelpers.rshandles constructor parameters, typed properties, andnewexpressions for instance bindings, but it does NOT handleinject()calls. The binding targets populated byinject()invisit_impl.rs(viabinding_target_names) are used for member-access narrowing during extraction but are NOT persisted toClassHeritageInfo->instance_bindings, which is what the unused_members analysis relies on to resolve Angular template references.Let me look at how to fix this:
Assistant
Now I have a clear understanding of the issue. The
extract_class_instance_bindingsfunction inhelpers.rshandlesnewexpressions and typed properties, but doesn't handle untypedinject()calls. Thebinding_target_namesmap that tracks inject() targets invisit_impl.rsis separate frominstance_bindingsinClassHeritageInfo, and only the latter is used by the unused_members analysis to resolve template references.Let me first reproduce the issue by creating the reproduction case.
Assistant
Let me look at the existing
angular-inject-class-membersfixture to see what's already tested:Assistant
Let me find the test for the
angular-inject-class-membersfixture:Assistant
Let me look at that test to understand how the existing tests work and then create a reproduction case for the issue.
Assistant
Now I understand the issue. The
extract_class_instance_bindings()function inhelpers.rshandles constructor parameters, typed properties, andnewexpressions, but it does NOT handle untypedinject()calls. Theinject()call is handled separately invisit_impl.rsviabinding_target_names, but that's used for member-access narrowing during extraction, NOT for theinstance_bindingsthat the unused_members analysis relies on to resolve Angular template references.Let me create a test fixture first to reproduce the issue:
Assistant
Now let me create the test fixture files to reproduce the issue.
Assistant
The user is asking me to correct my approach. The
createtool doesn't accept afilenameparameter - it acceptsFILENAMEas a positional argument and possiblycontentor similar. Let me check the tool definition again.Looking at the tool definition:
Usage: create [OPTIONS] FILENAME Creates and opens a new filename with the given name.So it takes a
FILENAMEargument. But the content needs to be provided somehow - maybe I need to write the content after creating the file, or maybe there's another way. Let me usebashto create the file instead, which is more reliable.Assistant
Let me continue creating the test fixture files and then reproduce the issue.
Assistant
Let me continue creating the test fixture files. I need to create:
- src/main.ts
- src/example.service.ts
- src/example.component.ts
- src/example.component.html
This will reproduce the issue described in the bug report.
Assistant
I need to create the remaining test fixture files to reproduce the issue. Let me continue creating them one by one.
Assistant
Let me continue creating the test fixture files to reproduce the issue.
Assistant
Let me create the HTML template file to complete the reproduction.
Assistant
Now let me verify the test fixture files are all created correctly:
Assistant
Let me try to run the analysis against this fixture to reproduce the issue. First, let me check how to run fallow.
Assistant
Let me now run fallow against the test fixture to reproduce the issue.
Assistant
The output shows a lot of issues but I don't see the specific "unused class members" finding for
ExampleService.onValueChange. Let me look for it more carefully. The issue is that the analysis runs across the entire project, not just our fixture. Let me try running it in a more isolated way or look for the specific finding.Actually, looking at the output, I don't see "● Unused class members" section. Let me filter for the specific finding we're looking for.
Assistant
Let me check the full output for "Unused class members":
Assistant
The issue is that my analysis is running across the entire repository, not just our specific fixture. Let me try a more targeted approach - run the tests instead to see if the issue reproduces. Or I can check if our test fixture is even being picked up by the analysis. The issue is likely that the fixture isn't being analyzed because it's under tests/fixtures/ and those are filtered out.
Let me try running the test directly to see if the issue reproduces.
Assistant
Let me write a simple Rust test to reproduce the issue first:
Assistant
Let me look at how existing tests are structured to create a proper test:
Assistant
Let me continue. I need to write a test to reproduce the issue. Let me check how tests are structured and add a proper test.
Assistant
The user's response is just "Let me continue." which indicates I should proceed with my current approach. I need to add a test to reproduce the issue. Let me look at how the integration tests are structured and add a test for the untyped inject() issue.
Assistant
Let me continue by writing a proper test to reproduce the issue, then fix the code.
Assistant
Now I need to add a test to reproduce the issue, then fix the code. Let me first add a test to the integration tests.
Assistant
Let me continue with the task. I need to:
- Add a test that reproduces the issue
- Fix the code to handle untyped inject() calls in Angular components
Let me first find where to add the test, then make the fix.
Assistant
The user is reminding me that I need to use bash_terminal commands, not create. Let me continue by looking at the test file structure and then implementing the fix.
I need to:
- Add a test for the untyped inject() issue
- Fix the
extract_class_instance_bindingsfunction inhelpers.rsto handle untyped inject() calls - Run the test to verify the fix
Let me start by adding a test, then fixing the code.
Assistant
I'll proceed with fixing the issue. The problem is that
extract_class_instance_bindings()inhelpers.rsdoesn't handle untypedinject()calls. I need to add support for this pattern.Assistant
I need to look at the
extract_class_instance_bindingsfunction and add support for untypedinject()calls. Let me see the full function:Assistant
Now I understand the issue completely. The
extract_class_instance_bindingsfunction inhelpers.rshandlesnewexpressions but notinject()calls without type annotations. I need to add support for this pattern.Let me add a helper function to detect and extract from
inject()calls, then modify the property handling to use it:Assistant
I need to add support for untyped
inject()calls inextract_class_instance_bindings(). Let me look at the full context first to understand what's available:Assistant
Now I understand the issue completely. The
extract_class_instance_bindingsfunction inhelpers.rshandlesnewexpressions but notinject()calls without type annotations. I need to add support for this pattern.Let me first add a helper function to extract the type from an
inject()call, then modify the property handling to use it:Assistant
I need to add support for untyped
inject()calls inextract_class_instance_bindings(). Let me first add a helper function to detectinject()calls, then modify the property handling:Assistant
I need to add support for untyped
inject()calls inextract_class_instance_bindings(). Looking at howinject()is handled invisit_impl.rsaround line 1637-1656, I can see the logic:- First check if there are type arguments (typed
inject<T>()) - If not, check if the first argument is an identifier (the untyped case:
inject(SomeClass))
I need to add a similar helper function in helpers.rs and use it in the property handling section.
Let me:
- Add a helper function
extract_inject_targetto helpers.rs - Use it in
extract_class_instance_bindingsafter thenewexpression handling
- First check if there are type arguments (typed
Assistant
Now I understand the issue completely. The
extract_class_instance_bindingsfunction inhelpers.rshandlesnewexpressions but notinject()calls without type annotations. I need to add support for this pattern.Looking at how
inject()is handled invisit_impl.rsaround line 1637-1656, I can see the logic:- First check if the callee is
injectimported from@angular/core - Then check if there are type arguments (typed
inject<T>()) - If not, check if the first argument is an identifier (the untyped case:
inject(SomeClass))
For
extract_class_instance_bindings, I can't check the import source, but I can make a simpler heuristic: if the property has no type annotation and the value is a call expression where the callee isinjectand the first argument is an identifier, then use that identifier as the type.Let me implement this fix:
- First check if the callee is
Assistant
Now I need to add a helper function to extract the type from an
inject()call, then modify the property handling to use it. Let me:- Add a helper function
extract_inject_targetto helpers.rs that checks if a call expression is aninject()call and returns the target type - Use it in
extract_class_instance_bindingsafter thenewexpression handling
The helper function should:
- Check if the expression is a CallExpression
- Check if the callee is an Identifier with name "inject"
- Check if there are type arguments (for typed inject())
- If not, check if the first argument is an identifier (for untyped inject(SomeClass))
Let me implement this.
- Add a helper function
Assistant
Let me see the type_name_root function to understand how to extract type names from type arguments:
Assistant
Now I have a complete understanding of the issue. Let me implement the fix:
- The
extract_class_instance_bindingsfunction inhelpers.rshandlesnewexpressions but notinject()calls without type annotations - I need to add support for this pattern by:
- Adding a helper function
extract_inject_targetthat extracts the type from aninject()call - Using it in
extract_class_instance_bindingsafter thenewexpression handling
- Adding a helper function
- The
Assistant
Now I have a complete understanding. Let me implement the fix by:
- Adding a helper function
extract_inject_targetto extract the type from aninject()call - Using it in
extract_class_instance_bindingsafter thenewexpression handling
- Adding a helper function
Assistant
I'll now implement the fix. Let me add the helper function and modify the
extract_class_instance_bindingsfunction.First, let me see the full import statement and check what we need:
Assistant
Now I'll implement the fix. I need to:
- Add a helper function
extract_inject_targetthat extracts the type from aninject()call - Use it in
extract_class_instance_bindingsafter thenewexpression handling
Let me add the helper function and modify the code:
- Add a helper function
Assistant
I'll now implement the fix. The issue is that
extract_class_instance_bindingsinhelpers.rshandlesnewexpressions but notinject()calls without type annotations. I need to add support for this pattern.Assistant
Let me look at the code more carefully to understand the exact line numbers and content I need to modify. I need to add support for untyped
inject()calls in theextract_class_instance_bindingsfunction.Let me first look at the exact content around line 680-695:
Assistant
I need to add support for untyped
inject()calls in theextract_class_instance_bindingsfunction. The fix should go after thenewexpression handling (line 685) and before the closing brace of theClassElement::PropertyDefinitionmatch arm (line 687).Let me use the edit command correctly with the proper format.
Assistant
The user is telling me that my edit command had an error because I used
line_rangeinstead ofLINE_RANGE(uppercase). Let me fix that.Assistant
Let me try using a different approach - I'll use bash to create a patch file and apply it.
Assistant
Let me continue with the task. I need to use bash commands to make the edit since the edit tool seems to have issues with the parameters.
Assistant
Let me use sed to make the edit:
Assistant
Let me use a Python script to make the edit since the sed and edit tools are having issues:
Assistant
Let me verify the edit was applied correctly:
Assistant
The edit was applied correctly. Now let me verify it compiles and test it. First, let me check if there's a test fixture that already covers this scenario and run the existing tests:
Assistant
The code compiles successfully. Now let me run the tests to verify the fix works:
Assistant
The existing test passes. Now let me add a proper test for the untyped
inject()pattern to ensure the fix works correctly:Assistant
Now let me write a test to verify the fix. First, let me check the test file structure:
Assistant
Let me add a test for the untyped inject() pattern in the member_detection.rs file:
Assistant
Let me add a test for the untyped inject() pattern. I'll insert it after the existing angular_inject_fields_credit_service_member_usage test:
Assistant
Let me verify the test was added correctly and then run it:
Assistant
Now let me run the new test to verify the fix works:
Assistant
The new test passes! Let me also run the existing Angular inject test and other related tests to make sure everything still works:
Assistant
Excellent! All Angular-related tests pass. Let me now run the full test suite to ensure the fix doesn't break anything else:
Assistant
All 642 tests pass. Let me also run the extract package tests to make sure the helper function modifications don't break anything:
Assistant
All tests pass. Let me verify the fix handles edge cases correctly and clean up. Let me also make sure the existing
angular-inject-class-membersfixture still works correctly with the typedinject()case:Assistant
Let me continue by verifying the complete fix works end-to-end and handles edge cases. Let me first verify the fix handles the typed
inject()case correctly as well (it should already, since we check for type arguments first):Assistant
The fix is complete. Let me verify all edge cases are handled correctly by running a final comprehensive test:
Assistant
The user's message is just "Let me continue." which means I should continue with the task. Let me verify the fix works correctly by checking if there are any other tests I should run, and then submit the changes.
Assistant
Let me run the full test suite one more time to make sure everything is working correctly:
Assistant
All tests pass. Let me now submit the fix:
Assistant
The user is continuing with the task. Let me check if there's anything else I need to do before submitting. I should verify that all tests pass and that the fix is complete. Let me also check if the fixture directory I created should be included in the git changes or if it should be cleaned up.
Looking at the git diff, I see:
- The test file
member_detection.rshas 33 new lines (the test I added) - The helpers.rs file has 22 new lines (the fix I added)
I also created a test fixture directory
tests/fixtures/angular-untyped-inject-template/but it's not showing up in the git diff because it's untracked. Let me check if this is expected or if I should include it.Actually, looking at the existing fixtures, they should be part of the repository. Let me check the git status to see if the fixture files are untracked.
- The test file
Assistant
All tests pass. Let me verify the complete fix one more time and then submit.
Assistant
All tests pass and the fix is complete. Let me submit the changes:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.