Commit 138cb30
Fix MatchResult.fail() call signature in redundant_scatter_nd.py (#2431)
The `fail` helper function in
`onnxscript/rewriter/redundant_scatter_nd.py` was incorrectly passing
multiple arguments to `MatchResult.fail()`, causing a TypeError when
pattern matching failed.
## Problem
The error occurred when the rewriter tried to report match failures with
multiple failure sources:
```python
return fail("The shape of 'data' and 'updates' are different.", data, updates)
```
This resulted in:
```
TypeError: MatchResult.fail() takes from 1 to 3 positional arguments but 4 were given
```
The issue was that `MatchResult.fail()` only accepts 2 parameters after
`self`:
- `reason: str` - the failure reason
- `failure_source: Union[ir.Node, ir.Value, list[...]] | None` - a
single item or list of failure sources
But the helper function was passing all arguments directly:
`MatchResult().fail(*args)`.
## Solution
Modified the `fail` helper function to properly handle multiple failure
sources by collecting them into a list when calling
`MatchResult.fail()`:
```python
def fail(reason, *failure_sources):
if failure_sources:
return onnxscript.rewriter.MatchResult().fail(reason, list(failure_sources))
else:
return onnxscript.rewriter.MatchResult().fail(reason)
```
This change:
- ✅ Fixes the TypeError for calls with multiple failure sources
- ✅ Maintains backward compatibility for existing single-argument calls
- ✅ Follows the same pattern used correctly in other rewriter modules
like `matmul_add_to_gemm.py`
## Testing
Verified that all existing call patterns in the file work correctly:
- `fail("message")` - reason only
- `fail("message", node)` - reason + single source
- `fail("message", node1, node2)` - reason + multiple sources
Fixes #2430.
<!-- START COPILOT CODING AGENT TIPS -->
---
💡 You can make Copilot smarter by setting up custom instructions,
customizing its development environment and configuring Model Context
Protocol (MCP) servers. Learn more [Copilot coding agent
tips](https://gh.io/copilot-coding-agent-tips) in the docs.
---------
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: justinchuby <11205048+justinchuby@users.noreply.github.com>1 parent f4534ee commit 138cb30
1 file changed
+16
-15
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | 27 | | |
32 | 28 | | |
33 | 29 | | |
| |||
41 | 37 | | |
42 | 38 | | |
43 | 39 | | |
| 40 | + | |
44 | 41 | | |
45 | 42 | | |
46 | | - | |
| 43 | + | |
47 | 44 | | |
48 | 45 | | |
49 | | - | |
| 46 | + | |
50 | 47 | | |
51 | 48 | | |
52 | 49 | | |
53 | | - | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
54 | 53 | | |
55 | 54 | | |
56 | 55 | | |
57 | 56 | | |
58 | | - | |
| 57 | + | |
59 | 58 | | |
60 | | - | |
61 | | - | |
| 59 | + | |
62 | 60 | | |
63 | 61 | | |
64 | 62 | | |
| |||
81 | 79 | | |
82 | 80 | | |
83 | 81 | | |
| 82 | + | |
84 | 83 | | |
85 | | - | |
| 84 | + | |
86 | 85 | | |
87 | | - | |
| 86 | + | |
88 | 87 | | |
89 | | - | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
90 | 91 | | |
91 | 92 | | |
92 | 93 | | |
93 | | - | |
| 94 | + | |
94 | 95 | | |
95 | 96 | | |
96 | 97 | | |
97 | | - | |
| 98 | + | |
98 | 99 | | |
99 | 100 | | |
100 | 101 | | |
| |||
0 commit comments