Skip to content
TheChatArchiveThe Chat Archive
MiniMaxminimax/minimax-m3· 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. MiniMax Assistant

    Let me start by exploring the repository structure to understand what we're working with.

  3. MiniMax Assistant

    Let me look at where Angular template references are handled and find the relevant code:

  4. MiniMax Assistant

    Let me search for "template" usage and Angular template handling in unused_members.rs:

  5. MiniMax Assistant

    Now let me search for the instance_bindings data structure:

  6. MiniMax Assistant

    Let me examine the helpers file to see how extract_class_instance_bindings works:

  7. MiniMax Assistant

    Let me look at the extract_class_instance_bindings function:

  8. MiniMax Assistant

    Now I have a clear understanding of the issue. Let me look at the test file for extract_class_instance_bindings:

  9. MiniMax Assistant

    Let me look at the full extract_class_instance_bindings function with line numbers:

  10. MiniMax Assistant

    Let me search for inject handling in the codebase:

  11. MiniMax Assistant

    Let me look at the existing extract_angular_inject_target function:

  12. MiniMax Assistant

    Now let me see how this extract_angular_inject_target is used:

  13. MiniMax Assistant

    Let me search for the existing test that confirms the typed inject case works:

  14. MiniMax Assistant

    Let me look at the integration test for angular template members:

  15. MiniMax Assistant

    Now let me reproduce the issue:

  16. MiniMax Assistant

    Let me look at the is_named_import_from method to understand it:

  17. MiniMax Assistant

    Let me look at the visitor/mod.rs:

  18. MiniMax Assistant

    Let me look at how extract_class_instance_bindings is called in the code:

  19. MiniMax Assistant

    Let me look at ImportInfo:

  20. MiniMax Assistant

    Let me search for how instance_bindings is used:

  21. MiniMax Assistant

    Let me also look at how angular tpl chain accesses work:

  22. MiniMax Assistant

    Let me check the existing imports in helpers.rs:

  23. MiniMax Assistant

    Let me look at the AST types involved:

  24. MiniMax Assistant

    Now let me look at the existing extract_angular_inject_target more carefully to ensure I follow the same logic:

  25. MiniMax Assistant

    Let me look at the existing tests for extract_class_instance_bindings:

  26. MiniMax Assistant

    Now let me look at the parse_ts function used in tests to see if it gives access to imports:

  27. MiniMax Assistant

    Let me look at a relevant existing test that tests instance_bindings:

  28. MiniMax Assistant

    Now I have all the context I need. Let me design and implement the fix.

    First, let me look at all callers of extract_class_instance_bindings to make sure I update them properly:

  29. MiniMax Assistant

    Now let me implement the fix. First, let me look at how helpers.rs is organized:

  30. MiniMax Assistant

    Let me also look at the type_name_root function:

  31. MiniMax Assistant

    Let me look at all uses of type_name_root:

  32. MiniMax Assistant

    Let me look for any existing helpers in helpers.rs that could extract type names:

  33. MiniMax Assistant

    Now I have a clear plan. Let me implement the fix. I'll first modify helpers.rs to:

    1. Add type_name_root as a helper function
    2. Add extract_angular_inject_target helper that takes imports as parameter
    3. Modify extract_class_instance_bindings to accept imports and use the new helper
  34. MiniMax Assistant

    Good. Now let me modify helpers.rs. First, I'll add the ImportedName import:

  35. MiniMax Assistant

    Let me try a different approach using replace:

  36. MiniMax Assistant

    Now let me update the extract_class_instance_bindings function and add helper functions. First let me re-read the function:

  37. MiniMax Assistant

    Now let me modify the function and add helpers:

  38. MiniMax Assistant

    Now I need to update the visitor method that uses type_name_root since I'm adding it to helpers. Let me check first:

  39. MiniMax Assistant

    Now let me update visit_impl.rs to use the new helper:

  40. MiniMax Assistant

    Now let me update the visitor method that uses the local extract_angular_inject_target:

  41. MiniMax Assistant

    Let me look at how the method is being used now and clean it up:

  42. MiniMax Assistant

    Let me just remove the wrapper method and update the call site directly:

  43. MiniMax Assistant

    Now I need to update all the callers of extract_class_instance_bindings to pass imports:

  44. MiniMax Assistant

    Now let me check the declarations.rs to find the context for the call:

  45. MiniMax Assistant

    Now let me update all the call sites:

  46. MiniMax Assistant

    Now let me build and verify the changes:

  47. MiniMax Assistant

    Let me clean up the unused import:

  48. MiniMax Assistant

    Now let me rebuild and test:

  49. MiniMax Assistant

    Now let me test the fix with the reproduction case:

  50. MiniMax Assistant

    Let me investigate the Angular template parsing to see if exampleService.onValueChange is being captured:

  51. MiniMax Assistant

    Let me first check if the existing tests pass for the typed version:

  52. MiniMax Assistant

    Good, the typed version works. Now let me try the untyped case:

  53. MiniMax Assistant

    The fix works. Let me now test more edge cases:

  54. MiniMax Assistant

    Excellent! All four scenarios pass. Let me also verify that non-Angular inject is not incorrectly treated as a binding:

  55. MiniMax Assistant

    Now let me add an unused method to verify the false positive is gone but real unused methods are still flagged:

  56. MiniMax Assistant

    Only the genuinely unused unusedMethod is reported. Now let me restore the original repro and run the existing tests to make sure I didn't break anything:

  57. MiniMax Assistant

    Now let me run the existing tests to make sure I didn't break anything:

  58. MiniMax Assistant

    Let me check if this failure is pre-existing (unrelated to my change):

  59. MiniMax Assistant

    The yarn test was flaky. Now let me run the extract tests specifically to make sure my changes are correct:

  60. MiniMax Assistant

    All extract tests pass. Now let me run the core tests:

  61. MiniMax Assistant

    All core tests pass too. Now let me write a proper test for the fix to add coverage:

  62. MiniMax Assistant

    Let me verify my changes are correct by re-reading them:

  63. MiniMax Assistant

    Let me check the entire diff:

  64. MiniMax Assistant

    I notice I accidentally removed a blank line. Let me fix that:

  65. MiniMax Assistant

    Good. Now let me verify the final state of the diff:

  66. MiniMax Assistant

    The diff looks good. Let me rebuild and run the tests:

  67. MiniMax Assistant

    Let me run the reproduction case once more:

  68. MiniMax Assistant

    Now let me run the tests to confirm nothing is broken:

  69. MiniMax Assistant

    The fix test failure is pre-existing and unrelated to my changes. Let me also verify my fix passes with the original Angular scenario by testing edge cases:

  70. MiniMax Assistant

    Let me test more edge cases:

  71. MiniMax Assistant

    Interesting! The dataService field is correctly flagged as unused because it's not referenced anywhere. The exampleService is correctly identified as used (because of the template reference).

    Let me try one more scenario - what about inject(SomeType) where SomeType is from another module:

  72. MiniMax Assistant

    The unused field is correctly flagged, and the used field is correctly not flagged. Now let me check the imports - if inject is imported with a different local name:

  73. MiniMax Assistant

    The aliased import works correctly. Let me also verify the combined case (constructor + inject):

  74. MiniMax Assistant

    Now let me run the integration test for Angular templates to confirm it still passes:

  75. MiniMax Assistant

    All Angular tests pass. Let me also check the clippy and formatting:

  76. MiniMax Assistant

    Now let me rebuild and re-verify:

  77. MiniMax Assistant

    The original reproduction case is fixed. Let me also run the original repro control cases to make sure they still pass:

  78. MiniMax Assistant

    All four cases (A, B, C, and the originally broken untyped inject) now report no issues.

    Let me also run the all-targets test one final time to make sure nothing else is broken:

  79. MiniMax Assistant

    The only failing test (fix_batch_aborts_when_a_target_directory_is_read_only) is a pre-existing flaky test that's unrelated to my changes - I verified this by stashing my changes and running the same test, which also fails.

    Let me also clean up the temporary test directory:

  80. MiniMax Assistant

    Now let me look at the final diff to confirm everything is clean:

  81. MiniMax Assistant

    Let me verify the edge case where inject is shadowed:

  82. MiniMax Assistant

    Interesting - in the edge case with shadowed inject, the binding still works correctly because the local inject returns its argument, so exampleService ends up being ExampleService. Let me clean up:

  83. MiniMax Assistant

    Let me do a final summary of the fix:

    Summary

    The issue was that when a component property is initialized with the modern Angular inject(SomeService) pattern (without an explicit type annotation), the property was not being recorded in the component's instance_bindings. This caused template references like exampleService.onValueChange(...) to not be credited to the ExampleService class.

    Root cause

    The extract_class_instance_bindings function in crates/extract/src/visitor/helpers.rs extracted property-to-type bindings for:

    1. Constructor parameters with accessibility modifier + type annotation
    2. Getter methods with return type annotations
    3. Property definitions with explicit type annotations
    4. Property definitions with new SomeConstructor() expressions

    But it did NOT handle property definitions initialized with inject(SomeService) from @angular/core.

    Fix

    The fix extends extract_class_instance_bindings to:

    1. Accept an imports: &[ImportInfo] parameter so it can determine whether inject is the named import from @angular/core.
    2. After handling the new expression case, check if the property value is a call expression to Angular's inject() function and extract the type name (either from the type argument inject<ExampleService>() or from the bare-identifier argument inject(ExampleService)).

    Files modified

    • crates/extract/src/visitor/helpers.rs:

      • Added ImportInfo, ImportedName, CallExpression imports.
      • Extended extract_class_instance_bindings to accept imports and detect inject(SomeService) calls.
      • Added extract_angular_inject_target helper (free function) that extracts the type name from an Angular inject() call.
      • Added is_named_import_from helper to check imports.
      • Moved type_name_root here from visit_impl.rs so the helpers module is self-contained.
    • crates/extract/src/visitor/visit_impl.rs:

      • Removed local type_name_root and extract_angular_inject_target methods (now using the helpers).
      • Updated all callers of extract_class_instance_bindings to pass &self.imports.
      • Updated visit_property_definition to use the new helper.
    • crates/extract/src/visitor/declarations.rs:

      • Updated caller of extract_class_instance_bindings to pass &self.imports.

    Verification

    • The original reproduction case now correctly reports "✓ No issues found" instead of falsely flagging ExampleService.onValueChange as unused.
    • All four patterns from the issue work correctly:
      • Constructor injection: ✓
      • Typed inject(): ✓
      • new initializer: ✓
      • Untyped inject(): ✓ (was broken, now fixed)
    • The non-Angular inject case (e.g., import { inject } from './container') is correctly NOT treated as a DI binding.
    • Aliased imports like import { inject as injectFromAngular } from '@angular/core' work correctly.
    • Genuinely unused methods on the service are still correctly flagged.

    Checklist Review

    Let me go through the checklist:

    1. If an error was reported in the issue description, I have successfully reproduced it. ✅ I reproduced the issue by creating the exact reproduction case from the issue and confirmed that ExampleService.onValueChange was reported as unused.

    2. If an error was reported in the issue description, I have confirmed that my fix resolves the error. ✅ I confirmed the fix by:

      • Re-running the original reproduction case - now reports "✓ No issues found"
      • Testing all four patterns from the issue (constructor, typed inject, new, untyped inject) - all work
      • Verifying the type-argument form inject<ExampleService>() works
      • Verifying the aliased import import { inject as ... } works
      • Verifying non-Angular inject is correctly NOT treated as DI binding
      • Verifying genuinely unused methods on the service are still correctly flagged
    3. I have thought about edge cases and made sure my fix handles them as well. ✅ I tested:

      • The bare-identifier form: inject(ExampleService)
      • The type-argument form: inject<ExampleService>(ExampleService)
      • Aliased imports: import { inject as injectFromAngular } from '@angular/core'
      • Non-Angular inject: import { inject } from './container'
      • Mixed patterns (typed inject for one field, untyped for another)
      • Unused fields with inject() (still correctly flagged)
    4. I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. ✅ I ran:

      • cargo test -p fallow-extract - 1681 tests pass
      • cargo test -p fallow-core - 641 tests pass
      • cargo test -p fallow-core angular - all 9 Angular tests pass
      • cargo test --workspace --all-targets - all tests pass except a pre-existing flaky test (fix_batch_aborts_when_a_target_directory_is_read_only) which I verified was already failing before my changes (filesystem permission issue unrelated to my fix)
      • cargo clippy --workspace --all-targets - no warnings
      • cargo fmt --all -- --check - no formatting issues

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