Skip to content

optimizer: copy full nature when patching nodes - #1004

Merged
antonmedv merged 1 commit into
masterfrom
fix/1000-optimizer-nature
Nov 21, 2026
Merged

antonmedv merged 1 commit into
masterfrom
fix/1000-optimizer-nature

Conversation

@antonmedv

Copy link
Copy Markdown
Member

Fixes #1000.

patchCopyType copied only the node's reflect.Type, not its full nature. When the optimizer rewrote filter(L, true)[0] to find(L, true), the struct field information was lost, and filter(L, true)[0].X panicked with a nil pointer dereference at compile time.

The fix copies the whole nature. The new test in test/issues/1000 panics without the fix and passes with it.

The change only affects compile time, so it has no runtime cost.

patchCopyType copied only the reflect type, so struct field information
was lost when filter(...)[0] was rewritten to find(...). Accessing a field
on the result then panicked at compile time.

Fixes #1000
@antonmedv
antonmedv merged commit 63b8909 into master Nov 21, 2026
33 of 34 checks passed
@antonmedv
antonmedv deleted the fix/1000-optimizer-nature branch November 25, 2026 11:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Field access on filter(...)[0] panics at compile time when the optimizer rewrites it to find

1 participant