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 explore the repository structure to understand what we're working with.
Assistant
The angular plugin doesn't seem to be where the template property binding is resolved. Let me look at the template member resolution code.
Assistant
Let me look at the template-related logic, especially around instance_bindings and where the property-to-type binding is resolved. Let me search for where
injectis handled, and where the property type resolution happens.Assistant
I found the key logic. The
extract_class_instance_bindingsfunction handles type annotations, constructor params, getters, andNewExpressioninitializers, but notinject()calls. Let me look at the relevant AST types.Assistant
Now let me look at the PropertyDefinition case more closely and add handling for
inject()CallExpression. Let me check whatis_builtin_constructordoes and the structure of CallExpression.Assistant
Now I'll add handling for the
inject()CallExpression in the PropertyDefinition branch. Let me view the exact lines to edit.Assistant
Now I'll add handling for the
inject()CallExpression. Let me edit the PropertyDefinition branch:Assistant
Now I need to add the helper functions
is_inject_callandextract_first_argument_type_name. Let me check theextract_static_expression_nameand related functions to understand patterns.Assistant
Let me add the helper functions. Let me view around
is_builtin_constructor:Assistant
Now let me add the helper functions right after
is_builtin_constructor:Assistant
I accidentally added a duplicate
#[cfg(test)]. Let me fix that:Assistant
Let me check the
Argumentenum structure in oxc:Assistant
So
Argumentinherits allExpressionvariants plusSpreadElement. This means I can match onArgument::SpreadElementand otherwise treat the argument as anExpression. SinceArgumentinherits Expression variants, I can call directly on an only if takes . But since Argument inherits Expression variants, the same variant patterns exist on Argument.Assistant
Let me check how existing code converts
ArgumenttoExpression:Assistant
The
extract_static_expression_nametakes&Expression, not&Argument. Let me rewriteextract_first_argument_type_nameto match Argument variants directly:Assistant
Now let me build to check it compiles:
Assistant
My edit accidentally replaced the function's closing
}with). Let me fix that:Assistant
It compiles. Now let me build the whole project and set up the reproduction. Let me first build the CLI:
Assistant
Now let me create the reproduction. Let me check the existing fixtures structure to set up a repro:
Assistant
There's already a fixture
angular-inject-class-members. Let me look at it and the inherited-members fixture:Assistant
Let me look at the inherited-members fixture which has the working DI patterns:
Assistant
Now let me create the reproduction case in a temp directory:
Assistant
The fix works. Now let me verify the original bug exists before the fix by temporarily reverting, to confirm reproduction:
Assistant
It didn't reproduce even without the fix. Let me investigate — maybe the angular plugin needs node_modules, or the detection path differs. Let me restore my fix and add a genuinely unused method to verify detection runs:
Assistant
Even a genuinely unused method isn't flagged. The detection isn't running. Let me check the plugin activation and whether node_modules is needed:
Assistant
all_dependency_namesreads from package.json dependencies. The plugin activation usesis_enabled_with_filesoris_enabled_with_scripts. Let me check those to see if node_modules is required.Actually,
all_dependency_names()likely just reads from package.json fields, not actual installed packages. So the plugin should activate. But the repro shows no detection.Let me check
is_enabled_with_filesandis_enabled_with_scripts.Assistant
all_dependency_names()reads from package.json. Let me check that function.Assistant
The component and service are at
src/, notsrc/app/, so they're not auto-entries. Let me check the existing working fixture's structure more closely:Assistant
No
.fallowrc.jsonin that fixture. Let me check howcreate_configworks in the test harness — it might add entries differently. Let me look at the test common helpers.Assistant
Let me look at the unused_members analysis flow around the template handling:
Assistant
genuinelyUnusedisn't flagged, which means the service isn't being analyzed for unused members at all. Let me look at how classes are collected and which qualify for analysis:Assistant
Key check: if the module is an entry point, no members are flagged. Let me check whether
example.service.tsis being treated as an entry point. Let me run with debug logging:Assistant
Let me inspect with JSON output to understand the state:
Assistant
genuinelyUnusedisn't flagged either, suggestingExampleServicemay be inwhole_object_used_exports. Let me check how that's populated:Assistant
Let me check where
whole_object_usesis populated in the extract visitor:Assistant
That's not the main source. Let me search for where whole_object_uses is pushed in the main visitor — it's probably in the expression visitor where a bare identifier is used as a value (not a member access). Let me search more broadly.
Assistant
Let me find where a bare identifier used as a value is recorded as whole_object_use:
Assistant
Let me find where a bare identifier reference (like
ExampleServiceused as a value ininject(ExampleService)) gets recorded. Let me look atvisit_identifier_referencein visit_impl.rs.Assistant
Let me look at lines around 2940-3010 more carefully:
Assistant
Let me look at
visit_expressionor where bare identifiers used as values are tracked. Let me search for "Identifier" handling that pushes whole_object. Actually, let me look at lines 2990-3010.Assistant
Let me search for
visit_expressionor the handling of bare identifier expressions used as values:Assistant
Let me check
visit_call_expression(line 2584):Assistant
Let me check if there's special
injecthandling in visit_impl.rs:Assistant
There's already an
extract_angular_inject_targetthat handlesinject(). Let me see how it's used (line 1886):Assistant
So
visit_property_definitionalready handlesinject()viaextract_angular_inject_target, recording abinding_target_namesentry. But there are two mechanisms. Let me checkbuild_typed_instance_binding_targets:Assistant
There are two parallel mechanisms. My fix targets mechanism 1 (
instance_bindings), which is correct for template chain resolution. But I need to understand whygenuinelyUnusedisn't flagged. Let me check if bare identifiers used as call arguments get recorded as whole_object_uses:Assistant
Let me look at the existing test
whole_object_use_skips_all_membersto understand what triggers whole_object_use:Assistant
Let me look at the extract tests around line 280-320 where
Eis added to whole_object_uses to understand triggers:Assistant
These are specific cases (Object.values, for-in, spread, dynamic computed). None is a bare identifier as a call argument. Let me test empirically whether the inject pattern suppresses member analysis. Let me test Control A (constructor injection) with a genuinely unused method:
Assistant
With Control A (constructor injection),
genuinelyUnusedIS flagged andonValueChangeis correctly NOT flagged. So the fixture structure is fine and the angular plugin is active. Now let me re-test the untyped inject repro:Assistant
With untyped inject,
genuinelyUnusedis NOT flagged — a false negative. This meansinject(ExampleService)marksExampleServiceas whole-object-used. Let me checkis_named_import_fromand whether the inject detection requires resolved imports:Assistant
extract_angular_inject_targetrecordsbinding_target_names(mechanism 2), not whole_object_uses. So why isgenuinelyUnusednot flagged? Let me write a temporary scratch test in the extract crate to dump the component'swhole_object_uses,member_accesses, andbinding_target_names:Assistant
Interesting! With my fix,
INSTANCE_BINDINGS = [("exampleService", "ExampleService")]is correctly populated, andWHOLE_OBJECT_USES = []is empty. Let me re-run the untyped inject repro with the freshly rebuilt binary:Assistant
genuinelyUnusedis still not flagged even with my fix, soExampleServiceis being skipped entirely via another mechanism. Let me write a scratch integration test in fallow-core to directly observe what's happening:Assistant
Let me write a scratch integration test to observe the behavior directly:
Assistant
genuinelyUnusedis NOT flagged and the service isn't an unused export either. Let me verify the service file still has the genuinely unused method:Assistant
The
genuinelyUnusedmethod is outside the class body (after the closing}). That's why it's not flagged — it's not a class member. Let me fix the service file:Assistant
Now
genuinelyUnusedIS flagged (with my fix) andonValueChangeis NOT flagged (correctly credited). The earlier "No issues found" was becausegenuinelyUnusedwas accidentally outside the class body. Let me confirm the bug reproduces WITHOUT my fix:Assistant
The scratch test was stashed too. Let me pop the stash and verify the bug via the CLI binary by temporarily reverting just the helpers.rs source:
Assistant
Interesting — without my fix,
onValueChangeis NOT flagged (onlygenuinelyUnused). So the false positive may already be resolved in 2.87.0 via theextract_angular_inject_target/binding_target_namesmechanism. Let me investigate what creditsonValueChange. Let me restore my fix first, then examineresolve_bound_object_name:Assistant
Let me check when
extract_angular_inject_targetwas added via git log:Assistant
extract_angular_inject_targetwas added in v2.60.0 (before 2.83.0). So the issue is puzzling. Let me add temporary debug output to the angular template chain access logic to see exactly what's happening:Assistant
Now WITHOUT my fix, the integration test shows
onValueChangeIS flagged (false positive!) andheritage_count=0 bindings=[]for the component — the bug reproduces in 2.87.0. My earlier CLI result was a mistake. Let me restore my fix and re-run:Assistant
My fix works: with the fix, the component's
instance_bindingsis populated[("exampleService", "ExampleService")], andonValueChangeis correctly credited (onlygenuinelyUnusedis flagged). Now let me remove the debug output and scratch test:Assistant
Let me verify everything is clean:
Assistant
tests.rshas 1 leftover addition. Let me check the end of the file:Assistant
Let me remove the trailing blank line:
Assistant
Now the only change is
helpers.rs. Let me view the final diff and confirm the change is correct:Assistant
The diff is clean. Now let me consider edge cases and run the relevant existing tests. Let me run the extract visitor tests and the angular template/member integration tests:
Assistant
All angular tests pass. Let me look at the existing
member_detection::angular_inject_fields_credit_service_member_usagetest to understand existing coverage:Assistant
The existing
angular_inject_fields_credit_service_member_usagetest uses aprivateinject property (skipped byextract_class_instance_bindings), so it's unaffected. Let me run broader member detection and false-positive tests:Assistant
All passing. Let me run the full extract test suite and a broader set of core integration tests to ensure no regressions:
Assistant
All 641 integration tests pass. Let me run the core library unit tests (which include the
unused_membersunit tests):Assistant
All tests pass. Let me do a final end-to-end verification with the CLI on the exact issue reproduction (service with only
onValueChange):Assistant
The exact issue reproduction now reports "✓ No issues found" — the false positive is resolved. Let me verify there are no compiler warnings and do a final review:
Assistant
There's a clippy
match_same_armswarning. Let me view it and fix it:Assistant
The
Argument::SpreadElement(_) => Noneand_ => Nonearms are identical. Let me restructure to avoid the warning while keeping clarity:Assistant
No more warnings. Let me rebuild the CLI, re-verify the repro, and re-run the angular tests to confirm everything still works:
Assistant
The behavior is exactly as expected. Let me run the angular tests one final time to confirm no regression after the restructure:
Assistant
All tests pass. Let me do a final review of the complete diff:
Assistant
The diff is clean — only the intended change to
helpers.rsremains. All temporary scratch files and debug code have been removed.Let me run a final clippy check on the whole workspace area I touched to be thorough:
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.