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
I'll start by exploring the repository structure to understand the codebase and locate relevant files for the issue. Let's begin.
- Assistant
Let me get a better overview of the project structure.
- Assistant
This is a Rust project (Cargo.toml). Let's explore the crate structure.
- Assistant
This is a Rust project. The issue is about Angular templates and
inject()pattern. I need to find the code that handles Angular template analysis and the component property → service-type binding step. Let's search for relevant files. - Assistant
Let me look for Angular-related code and specifically files that deal with template analysis and inject() patterns.
- Assistant
Let me check the Angular plugin and related test files.
- Assistant
Let me look at the test file for Angular template members:
- Assistant
Let me look at the test fixture for angular-template-inherited-members:
- Assistant
Let me explore that directory.
- Assistant
Let me explore the test fixture:
- Assistant
Let me check the data-view.component.ts and data.service.ts files in the test fixture to see how they handle the inject pattern.
- Assistant
This test fixture uses constructor injection (
public dataService: DataService), which works. The issue is that the untypedinject()pattern doesn't work. Let me look at the code that resolves the component property → service-type binding. Let me search for where Angular template member resolution happens. - Assistant
Now I need to understand how the Angular template member resolution works. Let me search for where component properties are resolved to their types.
- Assistant
Let me search for where the analysis of class members and templates happens.
- Assistant
The key file is likely
/fallow/crates/core/src/analyze/unused_members.rs. Let me examine it. - Assistant
Let me open this file and look for where component properties are resolved to their types. This is where the issue likely is.
- Assistant
Let me search for where template references are credited in the codebase.
- Assistant
Let me search for "angular" in the unused_members.rs file to understand how angular templates are handled.
- Assistant
Let me read the section that handles Angular template references:
- Assistant
Now I see the key logic. Let me understand how
component_bindingsandinstance_bindingswork. Thecomponent_bindingsmap is built fromclass_heritage.instance_bindings. Let me search for where instance_bindings are populated: - Assistant
Let me look for where instance_bindings are populated:
- Assistant
Now I need to find where
extract_class_instance_bindingsis defined to understand how it determines the bindings: - Assistant
Let me look at the
extract_class_instance_bindingsfunction: - Assistant
Let me see the full function.
- Assistant
Now I can see the issue! In the
extract_class_instance_bindingsfunction, when it processesPropertyDefinitionelements, it has two cases:- If there's a type annotation, it uses that
- If the value is a
NewExpression, it extracts the callee name
But there's no handling for when the value is a
CallExpressiontoinject(). Theinject()function returns a type based on its type argument, so when we have:tsreadonly exampleService = inject(ExampleService);We need to:
- Detect that the initializer is a
CallExpressiontoinject - Extract the type argument from the
inject()call (which isExampleService) - Add a binding from
exampleServicetoExampleService
Let me look at the code more carefully and understand how to implement this fix.
First, let me check if there's already handling for
inject()calls anywhere: - Assistant
Now I understand the issue. Let me look more carefully at the property definition handling and also understand what patterns are currently supported:
- Assistant
Let me see the rest of the PropertyDefinition handling and the helper functions:
- Assistant
Now I understand the code structure. The
extract_class_instance_bindingsfunction handles:- Constructor parameters with type annotations
- Property definitions with type annotations
- Property definitions with
newexpressions
But it's missing handling for
inject()calls without type annotations. Let me look at howinject()calls appear in the AST: - Assistant
Let me look at the existing test fixtures for inject patterns:
- Assistant
Let me look at the angular-inject-class-members fixture:
- Assistant
Let me look at the test case for angular-inject-class-members to understand what's currently tested:
- Assistant
Now let me check the test for this fixture:
- Assistant
Let me search for the test that uses this fixture:
- Assistant
Let me look at the test for angular-inject-class-members:
- Assistant
Let me look at that test case:
- Assistant
Now I understand the full picture. Let me look at the angular-template-complexity fixture since it has inject():
- Assistant
Let me look at the permissions component to understand the inject patterns:
- Assistant
Let me look at the template:
- Assistant
Let me check the test for this fixture:
- Assistant
Let me check the health test to see what it tests:
- Assistant
Let me look at these tests:
- Assistant
Let me look at more of the test:
- Assistant
OK, so the health test is about complexity, not dead-code. Let me search for the dead-code test related to the angular-template-complexity fixture.
- Assistant
Let me check the health test around line 735:
- Assistant
Let me now search specifically for where the inject() pattern is being handled in the context of templates. Let me check the existing test for the
angular-template-inherited-membersfixture more carefully: - Assistant
So in this fixture,
dataServiceis injected via constructor injection:constructor(public dataService: DataService) {}. This works because the constructor parameter has a type annotation.The issue is when we use
inject()without a type annotation:readonly exampleService = inject(ExampleService);. In this case, theextract_class_instance_bindingsfunction doesn't detect the binding because:- There's no type annotation on the property
- The value is a
CallExpression(not aNewExpression)
So I need to add handling for
inject()calls in theextract_class_instance_bindingsfunction.Let me also check how the test for the angular-template-inherited-members fixture is set up:
- Assistant
Let me look at how
injectis detected in other parts of the codebase: - Assistant
The existing code at visit_impl.rs:1641 checks if
injectis imported from@angular/core. Let me look at that code. - Assistant
Now I can see there's already an
extract_angular_inject_targetfunction that handles extracting the type from aninject()call. Butextract_class_instance_bindingsinhelpers.rsdoesn't use this logic.Let me trace the full flow:
extract_class_instance_bindingsbuildsVec<(String, String)>- property name → type name- This populates
instance_bindingsonClassHeritage - In
unused_members.rs,component_bindingsmaps local names to type names - Template chain accesses like
exampleService.onValueChangeusecomponent_bindingsto resolve
So the fix should be in
extract_class_instance_bindings. Let me check what functions are available there: - Assistant
Let me look at that function:
- Assistant
Now let me also check the
is_builtin_constructorfunction since it's used to filternewexpressions: - Assistant
Let me look at the
extract_type_annotation_namefunction: - Assistant
Let me read that function:
- Assistant
Let me look at how the existing
extract_angular_inject_targetfunction works in visit_impl.rs: - Assistant
Let me look at the full function:
- Assistant
Now I have a clear understanding of the issue. Let me first reproduce the issue by creating a test fixture, then fix the code. Let me first look at what we need to modify:
- Assistant
Now I need to add the fix. The fix should add handling for
inject()calls in thePropertyDefinitioncase. I need to add a check forCallExpressiontoinject()after theNewExpressioncheck.Let me write the fix:
- Assistant
Let me verify the fix was applied correctly:
- Assistant
Good, the fix is applied. Now let me create a test fixture that reproduces the issue and run the existing tests to make sure I didn't break anything.
First, let me check if there are existing tests that test the
inject()pattern: - Assistant
Let me wait for the build to finish:
- Assistant
Good, the existing tests pass. Now let me look at the existing tests for the
injectfield mappings to understand what they test: - Assistant
Let me look at the test:
- Assistant
Now I need to check if the fix compiles and also run the angular template members test. Let me first check if it compiles:
- Assistant
Good, it compiles. Now let me run the existing tests:
- Assistant
Let me also run the angular template members test:
- Assistant
Good, the existing tests still pass. Now let me run the member detection test as well:
- Assistant
Now I need to create a test fixture that reproduces the exact issue. Let me create the test fixture:
- Assistant
Let me create the test fixture files:
- Assistant
Let me create the main.ts file:
- Assistant
Let me create the example.service.ts file:
- Assistant
Let me create the example.component.ts file:
- Assistant
Let me create the example.component.html file:
- Assistant
Now let me also create a .fallowrc.json file:
- Assistant
Now let me run a test to see if the issue is fixed. First, let me create a simple test script:
- Assistant
Now let me write a temporary test to verify the fix works:
- Assistant
Let me write a standalone test script to verify the fix:
- Assistant
All existing tests pass. Now let me create a test that specifically tests the fix for the issue. Let me add a test to the integration test file:
- Assistant
I'll add a new test to verify that the untyped
inject()pattern works for external templates. Let me add it to the end of the file: - Assistant
Let me use the edit command properly.
- Assistant
I see the edit removed the closing
}of the previous test. Let me fix that: - Assistant
Let me look at the current state of the file:
- Assistant
I see the issue - the closing
}for the second test is missing. Let me fix it: - Assistant
I see there's a duplicate. Let me fix it properly:
- Assistant
The file is messed up. Let me rewrite it entirely:
- Assistant
Now let me verify the file is correct:
- Assistant
Good, the file is correct. Now let me run the tests to see if the new test passes:
- Assistant
The new test passes. Now let me run the full test suite to make sure nothing is broken:
- Assistant
All 642 tests pass. Now let me also run the extract tests to make sure nothing is broken there:
- Assistant
All 1681 extract tests pass. Let me also run the core tests to make sure nothing is broken:
- Assistant
All tests pass. Let me also check the visitor tests specifically:
- Assistant
Let me also run the full test suite to make sure nothing is broken:
- Assistant
The
fix_batch_aborts_when_a_target_directory_is_read_onlytest failure appears to be a pre-existing issue unrelated to my changes. Let me verify by checking if it's related to my change: - Assistant
The fix_batch_aborts_when_a_target_directory_is_read_only failure appears to be a pre-existing issue unrelated to my changes. Let me verify by checking if it was already failing before my change:
- Assistant
Good, the
fix_batch_aborts_when_a_target_directory_is_read_onlytest fails without my changes too. This is a pre-existing issue unrelated to my changes. Let me restore my changes: - Assistant
Good, the test failure is pre-existing and not related to my changes. Now let me also check if there are instance_bindings tests that I should verify:
- Assistant
Let me look at the instance_bindings tests to see what patterns they test:
- Assistant
Let me also look at the tests around line 3245:
- Assistant
Let me also check if there are any tests for
inject()with type arguments: - Assistant
Let me also run the extract tests specifically to make sure the existing tests still pass:
- Assistant
All angular-related tests pass. Let me also run the full test suite one more time to make sure everything is good:
- Assistant
All tests pass. Let me now verify my changes one final time by reviewing what I've changed:
- Assistant
Let me review the full diff:
- Assistant
The diff looks good. I notice there's a small change in the test file - the
{{{{was changed to{{in the assertion message. This is because the heredoc syntax in the shell command was interpreting the braces. Let me check the original file to make sure this is correct: - Assistant
I accidentally changed the
{{{{to{{in the assertion message. The original had{{{{which would be interpreted as literal{{in the format string. Let me fix this by restoring the original test file and only adding the new test. - Assistant
Now let me add just the new test at the end of the file without modifying the existing content.
- Assistant
Let me verify the test passes:
- Assistant
All tests pass. Let me now run the full test suite one more time to make sure everything is good:
- Assistant
All 642 tests pass. Let me also run the extract tests to make sure nothing is broken:
- Assistant
All 1681 extract tests pass. Let me now review my changes one final time:
- Assistant
Good. Let me also verify the full diff looks correct:
- Assistant
The diff looks clean and correct. Let me also check if there are new files that need to be added:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.