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
I'll start by exploring the repository structure and locating the Angular-related code that resolves component property types for template references.
- Assistant
There's already an
angular-inject-class-membersfixture — I'll inspect that and the Angular plugin source next. - Assistant
rg is not found, let me use grep instead.
- Assistant
I'll read the Angular plugin and the template-member integration tests to see how property types are resolved.
- Assistant
Let me look at the angular plugin and how it resolves inject types, and the angular_template_members test.
- Assistant
The angular plugin itself might not be where the type resolution happens. Let me look at template_usage.rs and how class members are resolved.
- Assistant
The logic lives in
unused_members.rs— I'll inspect how typed instance chains andinject()are handled there. - Assistant
There's also something about component_bindings. Let me look at that area more carefully.
- Assistant
instance_bindingsis on class heritage — next I'll find where those bindings are extracted. - Assistant
Found it — I'll open
extract_class_instance_bindingsin the helpers. - Assistant
Root cause is clear: untyped
inject()initializers aren't handled. I'll check existing inject helpers and nearby tests next. - Assistant
Inject-field tool access is already handled elsewhere — I'll compare that path with instance bindings.
- Assistant
I'll inspect how
inject()is already wired into field member-access credit. - Assistant
The --include with path directory might not work.
- Assistant
There's already an
extract_angular_inject_targetfunction in visit_impl.rs. Let me look at that and how it's used for mapping field accesses. - Assistant
So
extract_angular_inject_targetis used for member access within TypeScript (this.inner.aaa → InnerService.aaa), butextract_class_instance_bindingswhich is used for template references doesn't ... - Assistant
I need to wire inject handling into
extract_class_instance_bindings; next I'll check its call sites and whether import context is available. - Assistant
There are a few ways to fix this:
- Assistant
And the third call site around 2232:
- Assistant
Looking at the non_angular inject test will show what must stay blocked.
- Assistant
I'll check whether
extract_class_instance_bindingsis used outside this visitor next. - Assistant
I'll check how the working angular-template-inherited-members fixture declares its service injection.
- Assistant
I'll review recent inject-related changes, then reproduce the bug and implement the fix.
- Assistant
I'll inspect
helpers.rsimports and property-definition handling so I can add inject resolution cleanly. - Assistant
I'll check how local class exports and instance bindings are finalized so we don't double-count inject.
- Assistant
I'll add inject handling on
ModuleInfoExtractorand wire it into all call sites. - Assistant
I'll bump the extraction cache version if inject changes light up different heritage bindings.
- Assistant
grep path issue again - need to use path properly
- Assistant
Implementing the inject initializer binding and bumping the cache version.
- Assistant
Need to goto the right place first.
- Assistant
Now I'll apply the replace.
- Assistant
Now update the extract_class_instance_bindings function.
- Assistant
I'll replace the function to take a resolver callback.
- Assistant
Now update the three call sites.
- Assistant
Need to open the declarations file first.
- Assistant
extract_angular_inject_targetis private tovisit_impl— I'll make it crate-visible so declarations can use it. - Assistant
Now update the three call sites.
- Assistant
Strange - it says file not modified but found the string. Maybe I need the current file open.
- Assistant
Let me try edit command instead
- Assistant
Now visit_impl.rs call sites.
- Assistant
I'll update both call sites in visit_impl.rs
- Assistant
Now the export default site.
- Assistant
Update the default export site.
- Assistant
Also need to handle renamed imports like
import { inject as angularInject } from '@angular/core'. extract_angular_inject_target already uses is_named_import_from with local name which checks for the imported name being inject - let me verify. - Assistant
Good. Now bump CACHE_VERSION and add a unit test for instance_bindings with inject.
Also check helpers tests if any call extract_class_instance_bindings.
- Assistant
Bump cache version.
- Assistant
I'll add a temporary repro (no repo tests) and build fallow to verify the fix.
- Assistant
Package name is fallow-cli with hyphen.
- Assistant
Build succeeded. Running the reproduction case next.
- Assistant
Need to cd into the directory.
- Assistant
Fix works for untyped inject. I'll also verify unused methods still flag and control cases stay green.
- Assistant
All control cases look good. Running the related existing tests next.
- Assistant
All tests pass. I'll double-check the pure repro and review the final diff.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.