You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Dec 26, 2025. It is now read-only.
package main
import (
"fmt"
)
type Node struct {
name string
}
type Nodes []*Node
type Graph struct {
nodes Nodes
}
func main() {
var graph Graph
var s *string
graph.nodes = Nodes{&Node{"hello"}, &Node{"world"}, &Node{"foo"}, &Node{"bar"}, &Node{"baz"}}
for i, n := range graph.nodes {
if i == 2 {
s = &n.name // foo.go:23:9: exporting a pointer for the loop variable n
}
}
fmt.Println(*s)
}
This is valid code because n takes new pointer values, so &n.name points correctly to different names.