> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Go Method Set

A method set in Go is the strict collection of methods attached to a specific type, primarily used to determine whether a type satisfies an interface. While method sets strictly dictate interface implementation, they do not strictly limit direct method invocation; Go provides syntactic sugar that allows pointer methods to be called directly on addressable value instances.

## The Rules of Method Sets

The Go specification defines method sets based on the receiver type and struct embedding rules:

1. **Value Type (`T`)**: The method set of a defined type `T` consists of all methods declared with a value receiver of type `T`, plus promoted methods with value receivers from embedded value fields (and all promoted methods from embedded pointer fields).
2. **Pointer Type (`*T`)**: The method set of a pointer type `*T` consists of all methods declared with a pointer receiver `*T`, all methods declared with a value receiver `T`, and all promoted methods from embedded fields.

## Syntax Visualization

```go theme={"dark"}
type Base struct {
    ID int
}

func (b Base) GetID() int { return b.ID }
func (b *Base) SetID(id int) { b.ID = id }

type Document struct {
    Base // Embedded field
    Title string
}

// Value receiver
func (d Document) Read() string {
    return d.Title
}

// Pointer receiver
func (d *Document) Write(title string) {
    d.Title = title
}
```

Based on the declarations above, the method sets are evaluated as follows:

* **Method set of `Document` (Value):** `Read()`, `GetID()` (promoted value method).
* **Method set of `*Document` (Pointer):** `Read()`, `Write()`, `GetID()`, `SetID()` (promoted value and pointer methods).

## Method Sets vs. Direct Invocation

It is critical to distinguish between strict method sets (used for interface assignment) and flexible method calls (used for direct invocation on variables).

When invoking a method directly on a variable, Go provides syntactic sugar for addressable values. If a method requires a pointer receiver (`*T`) but is called on an addressable value `v` of type `T`, Go implicitly translates the call to `(&v).Method()`.

```go theme={"dark"}
var d Document
d.Write("New Title") // Valid: Go translates this to (&d).Write("New Title")
```

Even though `Write()` is not in the method set of the value type `Document`, the call succeeds because `d` is an addressable variable in memory.

## Addressability and Interface Satisfaction

The strictness of method sets applies primarily to interfaces. When a value is assigned to an interface, it loses its addressability. If Go allowed a value type (`T`) to satisfy an interface requiring a pointer method, the compiler would need to implicitly take the address of the value inside the interface. Since interface values are not addressable, this would cause memory safety issues.

Therefore, `*T` methods are strictly excluded from the `T` method set for interface satisfaction.

Conversely, a pointer (`*T`) can always be safely dereferenced (`*p`) by the compiler to create a copy for a value receiver (`T`). Because this dereferencing is universally safe, Go includes `T` methods in the `*T` method set.

## Interface Method Sets

For interface types, the method set is exactly the set of methods explicitly declared within the interface definition, including any methods embedded from other interfaces. A concrete type `T` or `*T` implements an interface if and only if its method set is a superset of the interface's method set.

```go theme={"dark"}
type ReadWriter interface {
    Read() string
    Write(string)
}
```

In the context of the `Document` example:

* `*Document` implements `ReadWriter` because its method set contains both `Read()` and `Write()`.
* `Document` does **not** implement `ReadWriter` because its method set lacks `Write()`. Assigning a `Document` value to a `ReadWriter` variable results in a compile-time error, regardless of whether the original `Document` variable was addressable.

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Go Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
