This repository has been archived by the owner on Jul 22, 2024. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Expected: Print string "false"
Actual: panic: runtime error: invalid memory address or nil pointer dereference
This check (which I presume is intended to catch
nil
) is converting boolean false to nil. Mruby nil type isn't really a type and needs special care with themrb_nil_p
macro to handle it. IMO this is not a detail that go-mruby users should have to know.Hash is similarly affected
Sadly there isn't a particularly tidy way to handle this. An MrbValue may contain nil but
ValueType
has no way of expressing this. It will always look likeTypeFalse
.This patch introduces TypeNil as a go-mruby specific detail. In order to avoid collision with future types the max for uint32 is used (of which ValueType is an alias).
Tests for MrbValue.Type have also been added where possible. Some types don't appear to exposed to userland so these have been left commented.
During testing I also noticed that
Decode
handling is likely to trip up on nil types withunknown type
errors thrown. It's highly likely that at some point Decode will need to handle this and the most sensible option (IMO) would be to use golang zero types where necessary but that is beyond the scope of this PR.I stumbled on this while implementing the return helper referenced in #20.