Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-5· anthropicHugging 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. Claude Assistant

    Let's look at extract_class_instance_bindings and extract_angular_inject_target functions.

  3. Claude Assistant

    CallExpression is not imported. Let's check what's needed and add the branch.

  4. Claude Assistant

    Good, pattern matching Expression::CallExpression(call) works fine without explicit import since it's matched via Expression:: enum variant. Now let's edit the property definition branch.

  5. Claude Assistant

    Now edit lines 680-685 to add the inject() handling, and add helper function after.

  6. Claude Assistant

    Now let's check extract_type_name is defined in this file and check that type_arguments field exists on CallExpression in this oxc version.

  7. Claude Assistant

    Good, call.type_arguments field exists confirmed by other usage. Now build.

  8. Claude Assistant

    Builds successfully. Now let's build the whole workspace and run tests related to angular / instance bindings.

  9. Claude Assistant

    Now let's build the reproduction and test it.

  10. Claude Assistant

    The fix resolves the issue. Now let's verify old behavior was indeed broken before fix (sanity check with git stash), and check existing test suite.

  11. Claude Assistant

    Good, now reproduced correctly in a fresh directory. Let's restore the fix and rebuild.

  12. Claude Assistant

    Now let's fully verify: clear cache, test unfixed (stashed) vs fixed with clean cache each time.

  13. Claude Assistant

    Confirmed: unfixed reproduces the bug, fixed resolves it. Now let's check the three control cases still work, plus additional edge cases (typed inject, constructor injection, new expression, and inject with type argument inject<Foo>()).

  14. Claude Assistant

    Now let's test the three control patterns to ensure they still work, plus edge cases.

  15. Claude Assistant

    All variants pass. Now let's ensure that a case where the property is NOT injected from a DI service (e.g., inject of unrelated function, or unresolved false positive credit) doesn't cause wrongly crediting unrelated classes. Let's also run existing test suite.

  16. Claude Assistant

    All 1681 tests pass. Now let's run the core crate tests too.

  17. Claude Assistant

    All 641 tests pass. Let's run the full workspace test suite for good measure.

  18. Claude Assistant

    Confirmed this test failure is pre-existing (unrelated to our change, likely due to running as root where read-only directories don't block writes). Let's continue with the rest of the workspace tests to make sure nothing else fails.

  19. Claude Assistant

    All other tests pass; only the pre-existing unrelated fix_batch_aborts_when_a_target_directory_is_read_only fails (confirmed to fail identically without our change, due to root-user environment). Let's clean up temp test dirs.

  20. Claude Assistant

    The diff is clean and minimal. Let's also add a test fixture matching the repo's convention if such fixtures are used in CLI integration tests, to strengthen coverage — let's check if there's a place tests reference these fixtures.

  21. Claude Assistant

    No existing tests reference this pattern, consistent with the reported gap. The fix is complete, minimal, and verified.

  22. Claude Assistant

    Checklist review

    • If an error was reported in the issue description, I have successfully reproduced it. Yes. I built the exact repro from the issue (component with readonly exampleService = inject(ExampleService); and an external template referencing exampleService.onValueChange(...)) and confirmed with the unmodified codebase that fallow dead-code reports ExampleService.onValueChange as an unused class member, matching the issue exactly.

    • If an error was reported in the issue description, I have confirmed that my fix resolves the error. Yes. After applying the fix (teaching extract_class_instance_bindings in crates/extract/src/visitor/helpers.rs to recognize an untyped inject(ServiceType) initializer on a class property, in addition to the existing type-annotation and new Expr() cases), the same repro now reports ✓ No issues found. I verified this by toggling the fix on/off via git stash/git stash pop with cache directories cleared between runs, so the difference is attributable solely to the code change.

    • I have thought about edge cases and made sure my fix handles them as well. Yes. I explicitly tested:

      • Control A (constructor injection) — still resolves correctly.
      • Control B (typed inject()) — still resolves correctly (unaffected, handled by the pre-existing type-annotation branch).
      • Control C (new ServiceType()) — still resolves correctly (unaffected, pre-existing branch, and I added an explicit continue after it so it can't fall through into the new branch incorrectly).
      • The exact repro (untyped inject()) — now resolves correctly.
      • An additional edge case, inject<ExampleService>(...) with an explicit generic type argument instead of relying on the argument identifier — resolves correctly via the type-argument branch I added, mirroring the existing extract_angular_inject_target logic used elsewhere in the codebase for a related (but distinct) DI-tracking purpose.
      • The change is scoped to ClassElement::PropertyDefinition only, consistent with how inject() is used in Angular (field initializers), and doesn't touch the separate this.foo chain-tracking mechanism (extract_angular_inject_target in visit_impl.rs), which already handled private/internal injected fields correctly and remains untouched.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. Yes. I ran cargo test -p fallow-extract (1681 passed), cargo test -p fallow-core (641 passed), and the full cargo test --workspace --no-fail-fast suite. All tests passed except fix_batch_aborts_when_a_target_directory_is_read_only, which I confirmed fails identically with or without my change (it's an unrelated, pre-existing environment issue — likely because the test relies on filesystem permissions to block writes, which doesn't work when running as root).

    I temporarily created reproduction directories under /tmp to validate the fix; these were removed before finishing, and no test files in the repository were modified or added.

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