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
Let me see the rest of this file and look at how templates are analyzed for Angular components
Assistant
Now let me look at how
instance_bindingsgets populated. This seems to be the key to understanding the issue.Assistant
I found the function
extract_class_instance_bindings. It handles:- Constructor parameters (with public/protected accessibility and type annotations)
- Getter methods (with return type)
- PropertyDefinition with type annotation
- PropertyDefinition with
newexpression
But it does NOT handle: 5. PropertyDefinition with
inject(...)expressionThe issue says the untyped
inject()is the only one that fails. Let me see how the type annotation is extracted to understand how inject is being parsed.Let me first look at the
extract_type_annotation_namefunction.Assistant
Now let me look at the
extract_type_annotation_namefunction in helpers.rs:Assistant
Now let me look at the existing fixture for "angular-inject-class-members" to understand how the typed version is being handled:
Assistant
Let me look at the test for this fixture to understand what scenario it tests:
Assistant
Let me look at how the Angular template scanner captures
exampleService.onValueChangeto understand what gets into member_accesses:Assistant
Now let me look at the visitor.visit_impl.rs to understand how these member_accesses and identifiers are turned into
ANGULAR_TPL_SENTINELentries:Assistant
let me look at how external templates get linked to the component:
Assistant
Now I understand the issue! Let me trace through the code:
- Template:
(input)="exampleService.onValueChange($event.target.value)" - Template scanner produces:
identifiers:{"exampleService"}member_accesses:[{object: "exampleService", member: "onValueChange"}]
- The HTML parser converts these to
MemberAccessentries where identifiers useANGULAR_TPL_SENTINELobject name and themember_accessesare kept as-is. - In
unused_members.rs, the chain accesses like(exampleService, onValueChange)are matched againstclass_heritage_by_filewhich containsinstance_bindingspopulated byextract_class_instance_bindings.
The bug is in
extract_class_instance_bindingswhich doesn't handle the untypedinject(...)initializer. Let me now confirm by looking at the rest of the unused_members code to verify my understanding:- Template:
Assistant
me first reproduce the bug to confirm:
Assistant
Now let me set up the reproduction:
Assistant
I confirmed the bug. Now let me verify the typed version works correctly:
Assistant
Now I have a clear understanding. The fix is to handle
inject(SomeService)inextract_class_instance_bindings. Let me look at the function more carefully:Assistant
Now let me look at how other parts of the code detect the
injectfunction from@angular/core:Assistant
There's already an
extract_angular_inject_targetfunction. Let me see how it's used:Assistant
Let me see how
extract_class_instance_bindingsis called:Assistant
Let me look at the helpers.rs imports to understand which AST types are available:
Assistant
me see where
binding_target_namesis used inunused_members.rs:Assistant
Let me see the full
extract_angular_inject_target:Assistant
Now let me design the fix. I need to add handling for
inject(...)calls inextract_class_instance_bindings. Let me write a small helper function and update the existing logic:Assistant
Let me check if
CallExpressionis imported in helpers.rs:Assistant
I need to import
CallExpressionfromoxc_ast::ast. Let me also check howextract_type_nameworksAssistant
Now let me write the fix. First, let me check the imports at the top of
helpers.rs:Assistant
Now let me implement the fix:
Assistant
Let me verify the changes:
Assistant
The changes look good. Now let me build and verify the fix works:
Assistant
Build succeeded. Let me test the reproduction:
Assistant
, the bug is still happening. Let me debug what's going on:
Assistant
me see how the class is visited and verify my understanding:
Assistant
me look at
record_exported_instance_bindingsto understand the flow:Assistant
me re-read the visit_class function in visit_impl.rs to see how it handles
instance_bindings:Assistant
me re-run the repro to confirm the fix worked. But wait, I already rebuilt - so let me run it again:
Assistant
Let me add some debugging to see what's happening:
Assistant
Hmm, no debug output. Let me check whether
extract_class_instance_bindingsis even being called. Let me add more aggressive debug:Assistant
Let me check whether
extract_class_instance_bindingsis called. Let me check the call sites:Assistant
The function isn't being called at all. Let me check if there's a different code path - maybe the component file is being handled differently. Let me check the parse path:Let me look at where parsing happens for files:
Assistant
Let me look more carefully at the visit_program flow:
Assistant
me see the current state of the file:
Assistant
The debug3.py didn't apply. Let me check:
Assistant
me add debug at the very top of the visitor to see if the file is being visited:
Assistant
Hmm, even
visit_programisn't being called! Maybe the build artifacts are stale. Let me try to clean and rebuild:Maybe the build artifacts are stale. Let me check:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && find target -name "*.rlib" | head -3]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
Let me continue with the debugging
Assistant
Still no debug output even with a clean build! Something is very wrong. Let me check the binary built correctly
Assistant
The strings are in the binary but they're not being printed. That means the visitor ISN'T being called. Let me check if the program is going through a different path.
Wait, maybe the issue is that the test fixture is using
parse_source_to_moduledifferently. Let me check the parse path. Actually maybe there's a different path - the Angular plugin might disable normal parsing?Let me check the discovery/parsing flow:Let me check the discovery/parsing flow:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && grep -rn "parse_source_to_module|parse_file|collect_module_info" crates/extract/src/ crates/core/src/ --include="*.rs" | head -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
So
parse_single_filecallsparse_source_to_modulewhich callsparse_source_to_module_inner(line 53 in parse.rs). Let me see the flow again.Actually wait, the strings ARE in the binary. So the debug prints are compiled in. But they're not showing up. That means the visit_program function isn't being called. Let me check the parse.rs path:Let me check more of parse.rs to see if there's some special handling for non-TS files:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && sed -n '128,200p' crates/extract/src/parse.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
So there's only one
visit_programdefinition. And it should be called byextractor.visit_program(...)at line 91 of parse.rs. Let me check if there's something wrong - maybe my debug wasn't actually inserted properly.Let me grep for the debug output to confirm:Let me check if the debug print is actually in the file:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && sed -n '1834,1850p' crates/extract/src/visitor/visit_impl.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Something is really strange. The visit_program function isn't being called at all. Let me try to add the debug in parse.rs directly to verify that the path is hit:Let me try to add the debug in parse.rs directly to verify that the path is hit:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && cat > /tmp/debug6.py << 'EOF' with open('crates/extract/src/parse.rs', 'r') as f: content = f.read()
Add debug at the parse_source_to_module_inner start
old_pattern = """fn parse_source_to_module_inner( file_id: FileId, path: &Path, source: &str, content_hash: u64, need_complexity: bool, ) -> ModuleInfo {"""
new_pattern = """fn parse_source_to_module_inner( file_id: FileId, path: &Path, source: &str, content_hash: u64, need_complexity: bool, ) -> ModuleInfo { eprintln!("DEBUG parse_source_to_module_inner: path={:?}", path);"""
content = content.replace(old_pattern, new_pattern)
Add debug at the visit_program call site
Assistant
The debug output isn't showing at all. This is very strange. Let me check if the debug is actually being added to the parse.rs:Let me check if the debug is actually being added to the parse.rs:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && grep -n "DEBUG" crates/extract/src/parse.rs | head]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Hmm, even after a full clean rebuild, the debug prints aren't showing! This is very unusual. Maybe the binary is being silenced somewhere. Let me check stderr redirection.
Wait - maybe the fallow binary detects its stderr and silences it somehow. Or maybe there's a panic in a worker thread. Let me check stderr manually:Let me check stderr manually:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /tmp/fallow-angular-repro && /fallow/target/debug/fallow dead-code --config .fallowrc.json 2>/tmp/stderr.log 1>/tmp/stdout.log && echo "==STDOUT==" && cat /tmp/stdout.log && echo "==STDERR==" && cat /tmp/stderr.log]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Interesting - the output is being routed to stderr. So the debug eprintln should also be in stderr. But it's not. So
parse_source_to_module_inneris NOT being called. That means there's some other path being used.Let me check the cache or the parse path. Maybe it's using a cached result:Let me check if there's a cache that might be returning stale results:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && ls crates/extract/src/cache* 2>/dev/null]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Found it! There's a cache that's being used. Let me check where the cache is stored:Found it! There's a cache that's being used. Let me check where the cache is stored:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && grep -rn "CacheStore::open|cache_dir|FALLOW_CACHE|fallow_cache" crates/ --include="*.rs" | head -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Found the cache! Let me delete it and try again:
Assistant
Excellent! The fix works! The bug is resolved. The cache was preventing the new code from running. After deleting the cache:
DEBUG extract_class_instance_bindings: prop=exampleService, type_annotation=false, value=Some(Discriminant(15))- this confirms the call expression is being detectedDEBUG visit_impl ClassDeclaration: ExampleComponent bindings=[("exampleService", "ExampleService")]- this confirms the binding is correctly created✓ No issues found- the bug is fixed!
Now let me remove all the debug prints:Excellent! The fix works! The bug is resolved. The cache was preventing the new code from running. Now let me remove all the debug prints:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && cat > /tmp/cleanup.py << 'PYEOF' import re
files = [ 'crates/extract/src/helpers.rs', 'crates/extract/src/visitor/helpers.rs', 'crates/extract/src/visitor/visit_impl.rs', 'crates/extract/src/parse.rs', ]
for path in files: try: with open(path, 'r') as f: content = f.read() # Remove eprintln! debug lines and any preceding comments I added content = re.sub(r'^[ \t]");\n', '', content, flags=re.MULTILINE) with open(path, 'w') as f: f.write(content) print(f"Cleaned {path}") except FileNotFoundError: print(f"Not found: {path}") PYEOF python3 /tmp/cleanup.py]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The cleanup didn't work because the regex didn't match the actual content. Let me try with a simpler approach:Let me clean up the debug prints manually:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && sed -i '/eprintln!("DEBUG/d' crates/extract/src/visitor/helpers.rs crates/extract/src/visitor/visit_impl.rs crates/extract/src/parse.rs && grep -n "DEBUG" crates/extract/src/visitor/helpers.rs crates/extract/src/visitor/visit_impl.rs crates/extract/src/parse.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All debug prints are cleaned up. Let me verify the file state is correct:
Assistant
Good, the changes are clean. Let me verify the imports are correct:
Assistant
Let me build and test again:
Assistant
The bug is fixed. Now let me also test the typed version still works:
Assistant
Let me also test other patterns:
Assistant
Genuinely unused methods are correctly reported. Now let me also test the untyped version with a genuinely unused method:
Assistant
Excellent! The fix correctly distinguishes between used and unused methods even with untyped
inject(). Let me also test other edge cases:Assistant
Type argument variant works. Let me also test
inject(SomeService, { optional: true })with optional flag:Assistant
Optional argument variant works too. Let me test that a user-defined
injectfunction is NOT matched (the heuristic should not false-positive):Assistant
, the user-defined
injectis NOT treated as DI, so neither method is falsely credited. Now let me test the case whereinjectis called with a non-identifier first argument:Assistant
The non-identifier case doesn't false-positive. The ExampleService is now unused because we couldn't match the inject call's first argument. This is correct behavior - we're being conservative.
Now let me also verify:
- constructor injection still works (already confirmed in issue)
- new initializer still works (already confirmed in issue)
- typed inject() still works (already confirmed)
Let me also test the existing test fixture:Let me also verify the existing test fixture still works:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && cargo test --workspace --test integration_test --no-fail-fast -- angular_inject 2>&1 | tail -20]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
All Angular-related tests pass. Let me also check if there's a more focused test for the angular template chain:
Assistant
This existing fixture uses
constructor(public dataService: DataService) {}for DataService, not theinject()pattern. So this test doesn't exercise the bug we're fixing.Let me also write a focused test to confirm my fix works. Wait, the rules say I can't modify existing tests. But I can create a temporary script to verify my fix works on edge cases. Let me check the issue description once more.
The issue says I shouldn't modify existing tests, but I can create new ones. Wait, no - the rules say "UNDER NO CIRCUMSTANCES should you modify existing tests or add new tests to the repository."
OK, so I shouldn't add new tests. Let me just make sure my fix is correct by running the existing tests.
Let me run the broader test suite to make sure nothing breaks:This existing fixture uses constructor injection, not the
inject()pattern. Let me run the broader test suite to make sure nothing breaks:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && cargo test --workspace --no-fail-fast 2>&1 | grep -E "test result:" | head -40]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
The only failing test is
fix_batch_aborts_when_a_target_directory_is_read_only, which is unrelated to my change. Let me verify this is a pre-existing failure:Let me check if this failure is pre-existing:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && git stash 2>&1 | tail -5 && cargo test fix_batch_aborts_when_a_target_directory_is_read_only 2>&1 | tail -20 && git stash pop 2>&1 | tail -5]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>Assistant
The test failure is pre-existing and unrelated to my change. Let me restore my changes:
Assistant
Good, my changes are restored. Let me run a final test to verify everything works:
Assistant
The diff is clean and focused. Let me verify the final state by running my repro test once more:
Assistant
The bug is fixed. Let me also run all the related tests once more to verify nothing else broke:
Assistant
All Angular and member-related tests pass. Let me also run the cli tests to make sure my change doesn't break anything:
Assistant
Only the pre-existing test failure (unrelated to my change). All other tests pass.
Let me also test the cargo build and clippy:Only the pre-existing test failure (unrelated to my change). All other tests pass.
Let me also test cargo build and clippy:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && cargo clippy --workspace --all-targets 2>&1 | tail -10]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
Clippy is suggesting I collapse the nested if. Let me do that:Clippy suggests I collapse the nested if. Let me fix that:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && sed -n '725,740p' crates/extract/src/visitor/helpers.rs]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
No warnings or errors. Let me run the repro one more time and also test the existing fixture:
Assistant
Let me also test the existing fixture:
Assistant
Assistant
The test passes. Let me also run all angular-related tests to verify:
Assistant
All Angular tests pass. Let me verify the final diff one more time:
Assistant
Let me also fix the comment which got cut off slightly:
Assistant
Now let me run the final check and verify everything works:
Assistant
Assistant
The fix correctly identifies the genuinely unused methods (
fooUnusedandbarUnused) while not reporting the used methods (fooUsedandbarUsed).Let me also test the case where inject is called with type arguments to confirm that variant still works:
Assistant
This shows:
InnerService.innerUsedis correctly credited (not in unused list) becausethis.inner.innerUsed()is used in outer.service.ts.InnerService.innerUnusedis correctly flagged as unused.
The pre-existing behavior for
this.inner.foo()viabinding_target_namescontinues to work.Note:
OuterService.forwardedis reported as unused because it's a top-level property that doesn't have any other references. That's expected behavior.Now let me also do final cleanup and verification:This shows:
InnerService.innerUsedis correctly credited (not in unused list) becausethis.inner.innerUsed()is used in outer.service.ts.InnerService.innerUnusedis correctly flagged as unused.
The pre-existing behavior for
this.inner.foo()viabinding_target_namescontinues to work.Note:
OuterService.forwardedis reported as unused because it's a top-level property that doesn't have any other references. That's expected behavior.Let me also do final cleanup and verification:]<]minimax[>[<tool_call> ]<]minimax[>[]<]minimax[>[cd /fallow && git status]<]minimax[>[]<]minimax[>[ ]<]minimax[>[</tool_call>
Assistant
The diff is clean and focused. Let me also check
cargo fmt --check:Assistant
Formatting is clean. Let me also run the broader tests one more time to make sure nothing breaks:
Assistant
All tests pass! Let me clean up the test artifacts:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.