# 无法将类型为 T 的变量 x 用作类型 *T 的参数传递给方法

- **ID:** `go/method-receiver-type-mismatch`
- **领域:** go
- **类别:** type_error
- **验证级别:** ai_generated
- **修复率:** 90%

## 根因

具有指针接收器 (*T) 的方法被使用值接收器 (T) 调用，反之亦然，参数类型与预期的指针或值类型不匹配。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |
| go1.23 | active | — | — |

## 解决方案

1. ```
   Take the address of the variable: method(&x) if the method expects *T
   ```
2. ```
   If the method expects T, dereference the pointer: method(*ptr)
   ```

## 无效尝试

- **Using a type assertion: x.(*T)** — Type assertion works on interfaces, not on concrete types; it will cause a compile error if T is not an interface. (95% 失败率)
- **Changing the method receiver to value type (T)** — If the method modifies the struct, changing to value receiver will cause those modifications to be lost. (80% 失败率)
- **Passing &x directly without checking if x is addressable** — If x is not addressable (e.g., return value of a function), &x will cause a compile error. (75% 失败率)
