Skip to content

Fix IsZero() panic#38

Open
smlx wants to merge 2 commits intoalecthomas:masterfrom
smlx:fix-iszero-panic
Open

Fix IsZero() panic#38
smlx wants to merge 2 commits intoalecthomas:masterfrom
smlx:fix-iszero-panic

Conversation

@smlx
Copy link

@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.
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()

1 participant