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 start by exploring the repository structure to understand the codebase.
Assistant
This is a Rust project (fallow). Let me look for the Angular plugin code.
Assistant
The template member resolution logic is elsewhere. Let me look at the integration tests and find where the component-property → service-type binding happens.
Assistant
Let me search for where the component property → service type binding happens.
Assistant
Let me find where the bound_targets map (component-property → service-type) is built.
Assistant
The key function is
extract_class_instance_bindings. Let me look at it.Assistant
I found the key function. It handles type annotations and
NewExpression, but notinject()call expressions. Let me check for any existinginjecthandling and understand the AST types.Assistant
Now I understand the AST patterns. There's already
extract_angular_signal_querywhich handles a CallExpression with Identifier callee and an Identifier argument. I should add similar handling forinject(SomeService)in the property definition branch.Let me look at how
injectmight be imported. Theinjectfunction is from@angular/core. We want to recognizeinject(ExampleService)as bindingexampleService→ExampleService. But we should be careful about false positives —injectcould be a different function. However, since this is an Angular-specific feature, and the typed instance binding is generally used for DI patterns, let me check whether there's some context about Angular being active.Actually, let me look at how the existing tests work and check whether
injectis recognized elsewhere. Let me look at the existing tests for instance_bindings.Assistant
Let me find tests that test the
newandinjectpatterns for instance bindings, to understand existing conventions.Assistant
inject()IS handled somewhere — but forthis.fieldmember access within the class. Let me look at these tests.Assistant
So
inject()is handled forthis.field.memberaccesses but NOT inextract_class_instance_bindings(which builds the component-property → service-type map used for templates). Let me find where thethis.inner.aaa→InnerService.aaamapping happens.Assistant
Now let me look at where the inject target is used (line 1886) and the surrounding context:
Assistant
Now let me understand how
extract_class_instance_bindingsis used in the template member resolution. Let me readpropagate_accesses_through_typed_instance_bindingsfully:Assistant
Let me look at how the template sentinel accesses are handled and trace the template flow.
Assistant
Now I understand the flow. The
component_bindings(line 1493) is built frominstance_bindingsproduced byextract_class_instance_bindings. The untypedinject()pattern is missed there. Let me look at the callers ofextract_class_instance_bindingsto understand what context is available.Assistant
Let me check how
this.field.membermember accesses are stored and howresolve_typed_instance_chain_targetsmatches them.Assistant
I see. So
this.field.aaaproduces a member access with objectthis(notthis.field)? No wait —this.inner.aaais a chain.visit_static_member_expressionforthis.inner.aaa: the outer member isthis.inner.aaa, object isthis.inner(a StaticMemberExpression), propertyaaa.static_member_object_name(&expr.object)whereexpr.objectisthis.inner. Let me checkstatic_member_object_name.Actually for
this.inner.aaa, the visit would:- visit
this.inner.aaa(StaticMemberExpression, object=this.inner, property=aaa).static_member_object_name(this.inner)—this.inneris a StaticMemberExpression whose object isThisExpression. Doesstatic_member_object_namehandle this? Probably returnsthis.inner? Let me check.
Actually this is the key: the
this.inneris a StaticMemberExpression with object ThisExpression. Let me checkstatic_member_object_name.- visit
Assistant
So for
this.inner.aaa,static_member_object_name(this.inner)returnsthis.inner. So the member access isobject="this.inner", member="aaa".Now there's likely a remapping step that converts
this.inner→InnerServiceusingbinding_target_names. Let me find that remapping.So the
this.inner.aaamember access has objectthis.inner. Then somewhere it's remapped toInnerServiceusingbinding_target_names["this.inner"] = "InnerService". Let me find this remapping.Assistant
Let me find the remapping of
this.inner→InnerServicein member accesses.Assistant
Now I need to find where
this.innermember access object is remapped toInnerService. Let me search where member_accesses objects starting withthis.get remapped via binding_target_names.Assistant
Let me search where member_accesses are post-processed to remap object names via binding_target_names, particularly for
this.prefixes.Assistant
Let me find where member accesses get remapped (post-processing). Let me search for the finalization.
Assistant
Let me look at
is_named_import_fromand how it's used.Assistant
Let me look at
type_name_rootand how the inject target extraction works to replicate it standalone.Assistant
Let me check the imports available in helpers.rs.
Assistant
Let me look at
extract_type_annotation_nameandextract_type_namein helpers.rs.Assistant
Now I have a clear understanding. Let me check the exact contexts of the three call sites to confirm they have
selfaccess.Assistant
Let me check test calls to
extract_class_instance_bindings.Assistant
Let me check if
extract_class_instance_bindingsis exposed publicly outside the crate.Assistant
I now have a full understanding. Let me make the fix. First, add
CallExpressionto the helpers.rs imports and modifyextract_class_instance_bindings.Assistant
Now let me make the edits. First, update the import in helpers.rs:
Assistant
Let me fix the import formatting properly with the edit command.
Assistant
Now let me modify the
extract_class_instance_bindingsfunction signature and add the inject handling. Let me view the function start:Assistant
Now let me add the helper functions
extract_inject_target_typeandts_type_name_root. Let me view the area after the function:Assistant
Now update the three call sites. First,
declarations.rs:Assistant
Now the two call sites in visit_impl.rs. Let me update them. There are two: line 1953 (
super::helpers::extract_class_instance_bindings(class);) and line 2235 (let bindings = super::helpers::extract_class_instance_bindings(class);).Assistant
Now let me build the extract crate to check for compile errors.
Assistant
is_named_import_fromis private. Let me check the module structure to understand visibility.Assistant
is_named_import_fromis private tovisit_impl. I'll make itpub(super)so the siblingdeclarationsmodule can access it.Assistant
Build succeeds. Let me verify both visit_impl.rs call sites were updated and check the context of line 1953.
Assistant
Both call sites are updated. Now let me build the full project and the CLI to reproduce the issue.
Assistant
Now let me set up the repro and test before/after the fix.
Assistant
The fix works. Let me verify the bug reproduces WITHOUT the fix by temporarily stashing my changes.
Assistant
Even without the fix, the repro reports "No issues found" — the bug isn't reproducing here. The Angular plugin may not be auto-activating. Let me check how enablers are detected (package.json vs node_modules).
Assistant
Let me find the default
is_enabled_with_depsimplementation in thedefine_plugin!macro.Assistant
Even without the fix the repro says "No issues found" — the bug isn't reproducing in this version (2.87.0 vs issue's 2.83.0). Let me check the extract crate's
parsetest helper to verify theinstance_bindingsbehavior directly.Assistant
Let me restore my fix and write a temporary test to verify the
instance_bindingsbehavior.Assistant
Let me check the
parse_tstest helper and add a temporary test to verify behavior.Assistant
Let me add a temporary test to the existing tests module to verify the behavior, then remove it.
Assistant
The fix works at the unit level. Let me verify the BEFORE behavior (without fix) to confirm the test would have failed:
Assistant
The stash removed the test additions too. Let me verify the before-behavior by temporarily reverting only the source file (helpers.rs), keeping the test.
Assistant
I need to revert all three source files together but keep the test additions. Let me do that.
Assistant
Confirmed: WITHOUT the fix,
instance_bindingsis empty[]for the untypedinject(ExampleService)pattern — that's the bug. Now let me restore my fix.Assistant
The end-to-end repro said "No issues found" even without the fix, which is puzzling. Let me investigate why — add a clearly unused method to verify the unused-member analysis is working.
Assistant
Interesting! Without the fix,
definitelyUnusedIS flagged butonValueChangeis NOT — soonValueChangeis being credited via SOME path even wheninstance_bindingsis empty. Let me investigate how external templates are scanned and credited. Let me find the external template scanningcode.Assistant
Let me find where HTML template content is parsed into
ANGULAR_TPL_SENTINELmember accesses.Assistant
Let me look at
external_style_usage.rsto understand how external HTML template files are scanned.Assistant
That's about external styles. Let me find where external HTML templates (Angular templateUrl) are parsed. The templateUrl is added as a SideEffect import, so the HTML file gets discovered and parsed. Let me find how HTML files are parsed in the extract pipeline and how their member accesses get associated with the component.
Let me search for where
.htmlextension is handled in parsing.Assistant
Let me find where external HTML template refs are collected and merged into the component module.
Assistant
Let me search broadly for where external template HTML content is read and scanned in the core analyze pipeline.
Assistant
I need to understand why
onValueChangeis credited even without the fix. Let me re-read theangular_tpl_chain_accessesblock carefully and checkclass_heritage_by_file.Assistant
Let me look at the initial member-access loop that builds
accessed_members.Assistant
I'm clearly missing a crediting path. Let me add temporary debug output to the
angular_tpl_chain_accessesblock to understand. First revert the fix to test original behavior.Assistant
Let me fix the debug line cleanly with python.
Assistant
Surprising! Even WITHOUT the fix,
component_bindingsHASexampleService → ExampleService! But the unit test showedinstance_bindingsempty. Let me investigate — there must be another path that populatesinstance_bindings(orcomponent_bindings). Let me search for whereinstance_bindingsmight be augmented frombinding_target_names.Assistant
There's a discrepancy: the e2e (original code) HAS the binding in
component_bindings, but my unit test showedinstance_bindingsempty. Let me restore the original unused_members.rs (remove debug) and find what populatesinstance_bindingsin the e2e path. Let me search for all writes toinstance_bindings.Assistant
Let me check the current state — did the stash fully revert the fix?
Assistant
git statusis clean — the stash holds my changes. So the debug run was on ORIGINAL code and showed the binding present. But the tmp unit test (on original code) showed empty. Let me look atparse_tsto see if it differs from the full pipeline.Assistant
Let me look at
parse_source_to_modulein parse.rs to see the full post-processing flow.Assistant
There's a contradiction I must resolve. The current tree is clean (original). Let me re-add debug and re-run the e2e to be 100% sure about the original behavior.
Assistant
On the CLEAN original tree, the e2e DOES have the binding! So
instance_bindingsIS populated somehow on original code. But my tmp unit test showed empty. Let me look atrecord_local_class_exportto see if it supplements instance_bindings frombinding_target_names.Assistant
Let me look at
into_module_infoand the post-processing that buildsclass_heritagefromlocal_class_exports.Assistant
There's
enrich_local_class_exports()— this likely augments instance_bindings. Let me look at it.Assistant
enrich_local_class_exportsjust copies fromextract_class_instance_bindings. The discrepancy is puzzling. Let me check if the CORE pipeline augmentsinstance_bindingsafter extraction.Assistant
Let me grep ALL of extract for any mutation of
instance_bindings(push/extend/assignment), includingLocalClassExportInfo.Assistant
Let me add a debug eprintln in
record_local_class_exportto see whatinstance_bindingsit receives in the e2e (original code).Assistant
No
DEBUG-REC-LOCALoutput —record_local_class_exportis never called! So the component's heritage comes via a different path. Let me see ALL debug output.Assistant
record_local_class_exportis never called, yetclass_heritagehas the binding. Let me find allclass_heritage.pushsites.Assistant
I'm confused. Let me check how
class_heritage_by_fileis constructed in unused_members.rs — it may not be fromclass_heritagedirectly.Assistant
Let me re-read the current (original) declarations.rs around the ClassDeclaration handling to settle the contradiction.
Assistant
Let me add debug directly inside
extract_class_instance_bindingsto see what it returns for each class in the e2e.Assistant
No
DEBUG-EXTRACT-IBoutput —extract_class_instance_bindingsis NEVER called in the e2e! Yetclass_heritagehas the binding. Let me find ALLClassHeritageInfo {construction sites.Assistant
The build didn't recompile fallow-extract! Let me verify my debug edit is actually in helpers.rs.
Assistant
Now it recompiled fallow-extract. Let me re-run the e2e.
Assistant
Still no DEBUG-EXTRACT-IB!
extract_class_instance_bindingsis never called yet the binding exists. Let me search the WHOLE repo for any mutation ofinstance_bindings, including the graph/types modules and any merge logic.Assistant
Let me check if fallow uses a parse cache that might be serving stale module info.
Assistant
Found it! There's a
.fallow/cache.bincaching the parsed ModuleInfo (keyed by source content, not binary). The cache was populated when my fix was active. Let me clear it and re-run on the original code.Assistant
The bug reproduces after clearing the cache. Let me see the full output on the original code.
Assistant
The bug reproduces on original code (cache was masking it). Now let me clean up all debug, restore original, and re-apply my fix from the stash.
Assistant
My fix is restored. Let me verify the fix is in place, rebuild, and run the e2e (cache cleared) to confirm it resolves the issue.
Assistant
The fix works:
onValueChangeis no longer flagged, but genuinely-unuseddefinitelyUnusedstill is. Let me verify the controls (constructor injection, typed inject,newinitializer) still work correctly and don't create false positives.Assistant
All four patterns resolve correctly with no false positives. Now let me remove the temporary tests I added to
tests.rs(I shouldn't add tests to the repo), then run the existing test suites.Assistant
Temporary tests removed. Now let me run the existing test suites to ensure no regressions.
Assistant
All extract tests pass. Now let me run the core tests, especially the Angular template members integration tests.
Assistant
All integration tests pass. Let me run the core lib unit tests too.
Assistant
All tests pass. Let me review the final state of my changes for cleanliness and check formatting.
Assistant
Let me check the
tests.rsdiff (shows 1 insertion — likely a stray newline from removing tmp tests).Assistant
There's a stray trailing blank line in tests.rs. Let me remove it so tests.rs is unmodified.
Assistant
tests.rs is now unmodified. Let me check the other two file diffs.
Assistant
All diffs look clean. Let me verify the build and run the relevant tests once more, then check formatting with rustfmt.
Assistant
rustfmt wants a different layout for the declarations.rs call site. Let me apply formatting.
Assistant
Formatting is clean. Let me run clippy on the extract crate to check for warnings, and rebuild the full binary.
Assistant
No clippy warnings. Let me rebuild the binary and re-run the full e2e repro to confirm everything still works after formatting.
Assistant
The fix works. Let me also run the exact issue repro (without the extra unused method) to confirm "No issues found".
Assistant
"No issues found" — matches the expected behavior. Let me verify a couple of edge cases: aliased inject import and a non-Angular inject (to ensure no false credit).
Assistant
Aliased inject works. Now let me verify the non-Angular inject case: a component importing
injectfrom a non-@angular/coresource should NOT credit the service via templates.Assistant
Non-Angular inject correctly does NOT credit the service. Let me confirm the
visitormodule visibility to ensure mypub(super)change doesn't leak externally.Assistant
pub(super)keeps it within thevisitorsubtree — no external leak. Let me do a final full workspace build and run the broader test suite to be safe.Assistant
There's a relevant existing test
angular_inject_fields_credit_service_member_usage. Let me look at it to make sure it's consistent with my change.Assistant
Let me look at the
angular-inject-class-membersfixture to ensure my change is consistent with it.Assistant
This existing fixture tests the
this.fieldpath with a private inject field (no external template) — my change skips private fields and doesn't touch that path, so it still passes. My fix is consistent with the existing design.Let me clean up temp files and do a final review of the complete diff.
Assistant
Let me view the complete final diff and run a final test pass.
Assistant
The diff is clean and complete. Let me do a final combined test run to confirm everything passes after all changes.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.