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 start by understanding the issue:
-
With the Angular plugin active,
fallow dead-codereports a service method as unused when:- It's only referenced in an Angular HTML template (
prop.method()) - The component property
propis initialized withinject()without an explicit type annotation
- It's only referenced in an Angular HTML template (
-
The fix should make untyped
inject()initializers resolve the same way as typed ones.
Let me first explore the repository structure to understand how it's organized.
-
Assistant
Let me explore more to understand the structure of the project and find relevant Angular-related code.
Assistant
This is a Rust project. Let me explore the crates directory and find the Angular-related code.
Assistant
The core crate likely contains the main logic. Let me look for Angular-related files.
Assistant
Let me look at the Angular plugin and the Angular template members test.
Assistant
Now let me look at the Angular SFC template handling and the visitor code for handling `inject
Assistant
Now let me look at where template member accesses are resolved to service class members. This is likely in the analysis phase.
Assistant
Let me look at unused_members.rs - this is likely where the template member accesses are resolved.
Assistant
Let me search for the specific areas in the codebase that handle template member access resolution and
inject:Assistant
Let me look at the key sections of unused_members.rs:
Assistant
Let me look further for how chain accesses are resolved:
Assistant
Let me search for how
instance_bindingsis populated:Assistant
Let me look at the
extract_class_instance_bindingsfunction:Assistant
Now I understand the issue. Let me look more at how
extract_class_instance_bindingsis called:Assistant
Let me look at the visit_impl.rs code around line 1952:
Assistant
Let me look at the test file for
extract_class_instance_bindings:Assistant
Let me look at the tests around line 3245 and 3315 to understand how instance_bindings are tested:
Assistant
Let me look at the
propagate_accesses_through_typed_instance_bindingsfunction and how it works:Assistant
Let me search for
build_typed_instance_binding_targets:Assistant
Let me look at that function:
Assistant
Let me look at the imports and structure of the helpers.rs file:
Assistant
Let me look at how
Argumentis used in the existing code:Assistant
Let me search for
injectin the codebase to see if there's already any handling:Assistant
Let me look at that method:
Assistant
Let me see the context around line 1886:
Assistant
Now I have a clear understanding of the issue. Let me first create a reproduction script to confirm the bug exists:
Assistant
Now let me try to run fallow to see if the issue reproduces. But first I should check if fallow is built. Let me check if there's a binary.
Assistant
Good, fallow is built. Now let me run it against the reproduction:
Assistant
Now I understand the issue. Let me look at the
type_name_rootfunction and what's available in helpers.rs:Assistant
Let me check what functions are available in helpers.rs for type name extraction:
Assistant
Let me look at
extract_type_name:Assistant
Now I have all I need. Let me also look at
extract_type_annotation_name:Assistant
Now I have a clear understanding. Let me implement the fix. The issue is in
extract_class_instance_bindingsin/fallow/crates/extract/src/visitor/helpers.rs. I need to add handling forCallExpressionvalues (likeinject(ExampleService)) when there's no type annotation.Assistant
The open command requires just a file path, not with line numbers. Let me use it correctly.
Assistant
The open command is different from what I expected. Let me use it properly.
Assistant
Let me go to the
extract_class_instance_bindingsfunction:Assistant
The goto command should be invoked differently. Let me try again.
Assistant
Now I can see the code I need to modify. Let me edit the
PropertyDefinitionbranch to add handling forCallExpression(likeinject(ExampleService)) after theNewExpressioncase:Assistant
Let me use the correct syntax for the edit command:
Assistant
The edit looks correct. Now let me rebuild and test
Assistant
It compiled successfully. Now let me test it against the reproduction case:
Assistant
The fix didn't work. Let me trace the issue more carefully. Let me check whether
class_heritagewith instance_bindings is actually being populated for the component:Assistant
Let me look at the existing test for inject field mapping:
Assistant
Let me look at the existing tests for instance_bindings:
Assistant
Let me search for tests related to instance_bindings with property definitions:
Assistant
Let me trace how the template URL connects the component to the template file. Let me search for
template_urlusage:Assistant
Let me look at how the template URL is processed in visit_impl.rs:
Assistant
Let me look at how HTML files are processed in the extract crate:
Assistant
Let me check how
declarations.rsandvisit_impl.rsinteract and which one populatesclass_heritage:Assistant
Let me look at how the
class_heritageis populated indeclarations.rs:Assistant
Let me check how the ModuleInfo is built to understand the flow:
Assistant
Let me look at parse.rs to understand the extraction flow:
Assistant
Let me look at
record_local_class_exportin visit_impl.rs and mod.rs:Assistant
Let me look at
record_local_class_export:Assistant
Let me look at this function:
Assistant
Let me look at how local_class_exports become class_heritage:
Assistant
Let me check where
record_exported_instance_bindingsis called:Assistant
Let me look at
enrich_local_class_exports:Assistant
Let me look at this function:
Assistant
Let me check where DeclarationExtractor is used:
Assistant
Let me search for the struct name:
Assistant
Let me check if declarations.rs is included:
Assistant
Let me look at the top of declarations.rs:
Assistant
Let me search for where functions from declarations.rs are called:
Assistant
Let me search for how the functions in declarations.rs are used:
Assistant
Let me look at
extract_declaration_exports:Assistant
Let me search for this function:
Assistant
Let me look at the full function:
Assistant
Let me look at
visit_declarationin visit_impl.rs:Assistant
Let me find where
extract_declaration_exportsis called:Assistant
Let me look at around line 2202 in visit_impl.rs:
Assistant
Let me look at the integration test for Angular template members:
Assistant
Let me look at the fixture for the angular-template-inherited-members test:
Assistant
Let me look at the fixture files:
Assistant
Let me look at the source files:
Assistant
Let me look at the component that uses the service:
Assistant
Let me search for how
class_heritage_by_fileis built:Assistant
Let me look at the context around line 1304:
Assistant
Let me check the function signature for
find_unused_members:Assistant
Let me look at the function signatures:
Assistant
Let me look at how Angular templates are parsed:
Assistant
Let me look at how
visit_classhandles Angular component metadata and class heritage:Assistant
Let me create a quick test script to verify that
extract_class_instance_bindingsworks correctly:Assistant
Let me run the existing tests to verify:
Assistant
Let me run the integration test for Angular template members:
Assistant
Let me check if there's a specific path for Angular components that might skip
extract_class_instance_bindings:Assistant
Let me add a temporary test to verify that
extract_class_instance_bindingsworks correctly. I'll add it to the tests file temporally:Assistant
Let me check if there are any tests for
extract_class_instance_bindingswith inject:Assistant
Let me look at the tests that involve instance_bindings:
Assistant
Let me search for tests related to
newexpression and instance_bindings:Assistant
Let me just run a broader search to find all tests related to class_heritage:
Assistant
Let me see all class_heritage references in tests:
Assistant
Let me look at line 248:
Assistant
Let me look at
visit_export_named_declaration:Assistant
Let me look at the full
visit_export_named_declarationfunction:Assistant
Let me see the rest of
visit_export_named_declaration:Assistant
Let me add a temporary debug print to verify the function is working:
Assistant
Let me try running with more verbose output:
Assistant
Let me verify the code I added is correct by looking at it:
Assistant
Let me use the proper command format:
Assistant
Let me clean and rebuild to make sure the changes are picked up:
Assistant
Now let me test again:
Assistant
Let me look at how
ResolvedModuleis built and whether it includesmember_accesses:Assistant
Let me check the Rust version:
Assistant
Let me check how HTML template file imports are resolved:
Assistant
Let me check how
has_angular_component_template_urlis used in the resolution:Assistant
Let me look at how
has_angular_component_template_urlis used in graph resolution:Assistant
Let me check how side-effect imports are resolved for HTML files:
Assistant
Let me search more broadly:
Assistant
Let me look at the narrowing.rs to understand how side-effect imports work:
Assistant
Let me look at
normalize_asset_url:Assistant
Let me look at this function:
Assistant
Let me look at how expressions are parsed in the Angular template scanner:
Assistant
Let me look at
collect_expression_refs:Assistant
Let me look at the
collect_unresolved_refs_and_accessesfunction:Assistant
Let me try running with more verbose output to understand what's happening:
Assistant
Let me look at the test fixture for the existing Angular template test that passes:
Assistant
Let me try with constructor injection to verify the template chain resolution works:
Assistant
Let me also verify that typed
inject()works:Assistant
Now let me verify the untyped case still fails:
Assistant
The fix works! The issue was that the previous test used cached module data. After changing the file, the cache was invalidated. Let me verify by doing a fresh test:
Assistant
The fix works. Now let me run the existing tests to make sure I didn't break anything.
Assistant
Existing inject tests pass. Let me run the Angular template members integration
Assistant
Let me run a broader set of related tests:
Assistant
All 302 extract tests pass. Let me also run the member detection integration tests:
Assistant
All tests pass. Let me clean up the temporary reproduction files:
Assistant
Let me do a final review of my change:
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.