{
  "id": "go/method-receiver-type-mismatch",
  "signature": "cannot use x (variable of type T) as type *T in argument to method",
  "signature_zh": "无法将类型为 T 的变量 x 用作类型 *T 的参数传递给方法",
  "regex": "cannot use .+ \\(variable of type \\w+\\) as type \\*\\w+ in argument to method",
  "domain": "go",
  "category": "type_error",
  "subcategory": null,
  "root_cause": "A method with a pointer receiver (*T) is being called with a value receiver (T), or vice versa, and the argument type doesn't match the expected pointer or value type.",
  "root_cause_type": "generic",
  "root_cause_zh": "具有指针接收器 (*T) 的方法被使用值接收器 (T) 调用，反之亦然，参数类型与预期的指针或值类型不匹配。",
  "versions": [
    {
      "version": "go1.20",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.21",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.22",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    },
    {
      "version": "go1.23",
      "introduced": null,
      "deprecated": null,
      "removed": null,
      "behavior_change": null,
      "status": "active"
    }
  ],
  "os_specific": {},
  "dead_ends": [
    {
      "action": "Using a type assertion: x.(*T)",
      "why_fails": "Type assertion works on interfaces, not on concrete types; it will cause a compile error if T is not an interface.",
      "fail_rate": 0.95,
      "condition": "",
      "sources": []
    },
    {
      "action": "Changing the method receiver to value type (T)",
      "why_fails": "If the method modifies the struct, changing to value receiver will cause those modifications to be lost.",
      "fail_rate": 0.8,
      "condition": "",
      "sources": []
    },
    {
      "action": "Passing &x directly without checking if x is addressable",
      "why_fails": "If x is not addressable (e.g., return value of a function), &x will cause a compile error.",
      "fail_rate": 0.75,
      "condition": "",
      "sources": []
    }
  ],
  "workarounds": [
    {
      "action": "Take the address of the variable: method(&x) if the method expects *T",
      "success_rate": 0.95,
      "how": "Take the address of the variable: method(&x) if the method expects *T",
      "condition": "",
      "sources": []
    },
    {
      "action": "If the method expects T, dereference the pointer: method(*ptr)",
      "success_rate": 0.9,
      "how": "If the method expects T, dereference the pointer: method(*ptr)",
      "condition": "",
      "sources": []
    }
  ],
  "workarounds_zh": [
    "Take the address of the variable: method(&x) if the method expects *T",
    "If the method expects T, dereference the pointer: method(*ptr)"
  ],
  "transition_graph": {
    "leads_to": [],
    "preceded_by": [],
    "frequently_confused_with": []
  },
  "official_doc_url": "https://go.dev/ref/spec#Method_sets",
  "official_doc_section": null,
  "error_code": null,
  "verification_tier": "ai_generated",
  "confidence": 0.87,
  "fix_success_rate": 0.9,
  "resolvable": "true",
  "first_seen": "2023-09-12",
  "last_confirmed": "2024-06-01",
  "last_updated": "2024-06-01",
  "evidence_count": 1,
  "tags": [],
  "locale": "en",
  "aliases": []
}