Skip to content
TheChatArchiveThe Chat Archive
x-ai/grok-4.5· unknownHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION service member referenced in an Angular external template is reported…

  1. 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 angular plugin active, fallow dead-code reports a service method as an unused class member when its only reference is in an Angular HTML template (prop.method()), and the component property prop is initialized with the modern inject() 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 patternTemplate 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/core only needs to be listed in package.json so the angular plugin auto-activates — running npm install is optional (without it, fallow prints a "node_modules directory not found" warning but the finding still reproduces).

    1. Create package.json:

      {
        "name": "fallow-angular-template-repro",
        "version": "1.0.0",
        "private": true,
        "dependencies": {
          "@angular/core": "^20.0.0"
        }
      }
      
    2. Create .fallowrc.json:

      {
        "entry": ["src/main.ts"]
      }
      
    3. Create src/main.ts:

      import { ExampleComponent } from './example.component';
      
      console.log(ExampleComponent);
      
    4. Create src/example.service.ts:

      import { Injectable } from '@angular/core';
      
      @Injectable({ providedIn: 'root' })
      export class ExampleService {
        // Only referenced from example.component.html via an event binding.
        onValueChange(value: string): void {
          console.log(value);
        }
      }
      
    5. Create src/example.component.ts:

      import { Component, inject } from '@angular/core';
      
      import { ExampleService } from './example.service';
      
      @Component({
        selector: 'app-example',
        templateUrl: './example.component.html',
      })
      export class ExampleComponent {
        // Exposed to the template so the binding can call exampleService.onValueChange(...)
        readonly exampleService = inject(ExampleService);
      }
      
    6. Create src/example.component.html:

      <input (input)="exampleService.onValueChange($event.target.value)" />
      
    7. Run:

      npx fallow dead-code --config .fallowrc.json
      

    Actual output

    ── Unused Code ─────────────────────────────────────
    
    ● Unused class members (1)
      src/example.service.ts
        :6 ExampleService.onValueChange
      Class methods or properties never referenced outside their class
    
    ✗ 1 class member
    

    onValueChange is reported as unused even though it is referenced in example.component.html.

    Controls that isolate the root cause

    Keeping the template (input)="exampleService.onValueChange(...)" unchanged and only varying how exampleService is declared on the component:

    • Control A — constructor injection: replace the inject() field with constructor(public exampleService: ExampleService) {}. Result: ✓ No issues found.
    • Control B — inject() with an explicit type annotation: readonly exampleService: ExampleService = inject(ExampleService);. Result: ✓ No issues found.
    • Control C — new initializer: readonly exampleService = new ExampleService();. Result: ✓ No issues found.

    Only the untyped inject() initializer (the repro above) produces the false positive. This points at the component-property → service-type binding step: it resolves type annotations, constructor parameters, and new expressions, but not an untyped inject() initializer, so the template reference exampleService.onValueChange is never credited to ExampleService.

    Expected behavior

    A service member referenced from an Angular template via a component property should be credited as used when that property is initialized with inject() — the same way it already is for typed inject(), constructor injection, and new initializers. No unused-class-member finding should be reported in the repro above.

    Fallow version

    fallow 2.83.0

    Operating system

    macOS

    Configuration

    default
    

    Interface

    No new interfaces are introduced.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /fallow, current file: none) bash-$

  2. Assistant

    I'll start by exploring the repository structure and locating the Angular plugin code that resolves component property types for template references.

  3. Assistant

    There's already an angular-inject-class-members fixture — I'll inspect it and search the Angular plugin for property-type resolution.

  4. Assistant

    rg is not found, let me use grep instead.

  5. Assistant

    I'll read the Angular plugin and the template-member tests next.

  6. Assistant

    The Angular plugin and template usage extraction are where class-member resolution happens — open those next.

  7. Assistant

    The angular plugin itself is mostly about entry points. The template usage is in extract. Let me look at template_usage.rs and search for inject-related handling.

  8. Assistant

    Let me look at angular_template_members test and how member detection works with inject.

  9. Assistant

    Let me look at unused_members.rs more carefully for Angular template handling.

  10. Assistant

    There's a visitor test for inject field mapping — I'll check how type bindings are extracted for constructors vs inject.

  11. Assistant

    Found extract_angular_inject_target — reading the inject and type-binding logic in the visitor next.

  12. Assistant

    Let me look at where inject is used for field bindings around line 1886.

  13. Assistant

    Inject bindings use this.{name}, but templates reference the bare property — checking how external-template chain resolution expects those bindings.

  14. Assistant

    Continue reading the angular_tpl_chain_accesses handling.

  15. Assistant

    The key is instance_bindings on class heritage — finding where those get populated.

  16. Assistant

    The key function is extract_class_instance_bindings in helpers.rs.

  17. Assistant

    Confirming this is the binding extraction path — keep reading for inject handling.

  18. Assistant

    Root cause is clear: extract_class_instance_bindings handles typed fields and new, but not inject(). Checking call sites and how inject import context is available.

  19. Assistant

    I'll inspect every extract_class_instance_bindings call site and how Angular inject imports are tracked.

  20. Assistant

    Checking existing instance_bindings tests and whether helper unit tests cover property initializers.

  21. Assistant

    instance_bindings also feed typed member propagation — checking that path before deciding how to detect inject.

  22. Assistant

    Checking helper unit tests and all extract_class_instance_bindings call sites so I can update the signature cleanly.

  23. Assistant

    Implementing inject resolution in extract_class_instance_bindings and wiring it through the three call sites.

  24. Assistant

    Need the right window position for the edit tool, then apply.

  25. Assistant

    Now I can edit.

  26. Assistant

    Updating call sites and exposing extract_angular_inject_target.

  27. Assistant

    Need to navigate first.

  28. Assistant

    Let me use sed for simpler replacements or replace command.

  29. Assistant

    The quotes are causing issues due to (_)). Let me use a herdoc form of replace.

  30. Assistant

    Now update the three call sites.

  31. Assistant

    Let me update all three with context.

  32. Assistant

    Updating all three call sites now.

  33. Assistant

    Now the default export call site.

  34. Assistant

    Update default export and declarations.rs

  35. Assistant

    Updating declarations.rs and checking whether export-named also records heritage elsewhere.

  36. Assistant

    For export named classes, class heritage comes from extract_declaration_exports. For local classes that become exports later via export { Foo }, there might be record_local_class_export path.

  37. Assistant

    Checking whether imports are recorded before export processing so inject resolution works.

  38. Assistant

    Compiling and verifying the extract tests compile/pass with this change.

  39. Assistant

    Compiling succeeded. Next I'll add a visitor unit test and reproduce the original issue.

  40. Assistant

    Let me open the tests file at the inject tests and add a new test.

  41. Assistant

    I'll add a test after the non_angular_inject test for instance_bindings. Note: private fields are skipped for instance_bindings, so the test needs a public/readonly untyped inject field.

  42. Assistant

    Instructions say not to add tests to如果 the repo — removing those unit tests and using a temporary repro instead.

  43. Assistant

    Restoring the #[test] attribute I accidentally removed.

  44. Assistant

    There may not be a blank line. Let me look at the file around that area.

  45. Assistant

    Need to fix the missing #[test]

  46. Assistant

    Creating a temporary repro of the original issue and running fallow against it.

  47. Assistant

    Good, built. Now run the tool on the repro.

  48. Assistant

    How do I specify the project root?

  49. Assistant

    --root is the flag.

  50. Assistant

    Untyped inject is fixed. Reach next: edge cases and the Angular integration tests.

  51. Assistant

    All edge cases look good. Running the Angular and visitor regression tests next.

  52. Assistant

    All related tests passed. Checking the diff and confirming tests.rs is clean.

  53. Assistant

    Wait - there's a potential timing bug. For export class processed via extract_declaration_exports during visit_export_named_declaration: are imports already registered? I understand the concern about timing for export class declarations and whether imports are registered before extract_declaration_exports runs. The current logic should handle both direct export class and `export { ...

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.