Skip to content

Fix IsZero() panic#38

Merged
alecthomas merged 2 commits intoalecthomas:masterfrom
smlx:fix-iszero-panic
May 1, 2026
Merged

Fix IsZero() panic#38
alecthomas merged 2 commits intoalecthomas:masterfrom
smlx:fix-iszero-panic

Conversation

@smlx
Copy link
Copy Markdown
Contributor

@smlx smlx commented Jan 5, 2026

Due to the automatic dereferencing that Go does when calling a method implemented with a value receiver on a pointer type, calling IsZero() on a nil pointer can panic.

This PR adds a test for this issue and a check to avoid it.

Closes: #37

smlx added 2 commits January 5, 2026 23:38
If a nil pointer to a type T that implements IsZero() with a value
receiver is passed to repr, it will panic due to the nil pointer being
automatically dereferenced in the IsZero() method invocation.
Check if IsZero() is implemented with a value receiver, and avoid
calling it if the value is a nil pointer because this will panic.
@smlx
Copy link
Copy Markdown
Contributor Author

smlx commented May 1, 2026

@alecthomas gentle ping: I would love to drop the replace clause from my go.mod 🙂

@alecthomas alecthomas merged commit 41e116c into alecthomas:master May 1, 2026
@alecthomas
Copy link
Copy Markdown
Owner

Thanks!

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.

Panic due to nil pointer to type that implements IsZero()

2 participants