Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(gnolang): allow comparisons using uninitialized string values (#1132
) The provided additional test, without the patch, fails with the following error: ``` === RUN TestFiles/comp3.gno Machine.RunMain() panic: interface conversion: gnolang.Value is nil, not gnolang.StringValue [...] goroutine 180 [running]: runtime/debug.Stack() /usr/lib/go/src/runtime/debug/stack.go:24 +0x65 [...] panic({0xb91680, 0xc001fa7bf0}) /usr/lib/go/src/runtime/panic.go:884 +0x213 github.com/gnolang/gno/gnovm/pkg/gnolang.isLss(0xc0054b4050, 0xc0054b4078) /home/howl/oc/gno2/gnovm/pkg/gnolang/op_binary.go:492 +0x431 ``` This seems to be because internally, the string value is "uninitialized" (hopefully right word here). This is in opposition to an initialised string, as would happen for the statement `x := ""`. This PR changes the behaviour for comparisons inside of `op_binary` (<, >, <=, >=) to use `GetString` instead of a type assertion of `TypedValue.V` to a `StringValue`. This is in line with what is already done inside of `isEql`, introduced in this commit: da6520f#diff-7cc5c6bc5496b6ad9ed55e04e1cdf2f0d1d5954af21be5bc38ef3c46389149a9L358 `git blame` points instead this part of code inside of the comparisons functions to go back to the initial commit. Additionally, I looked for other cases where we are currently doing type assertions directly into a `StringValue`, and there was one in the implementation of `append`. Since this is a special case and requires having a native value as the first argument, I haven't written a test for it, but the change should be safe as `GetString()` internally just does the type assertion, but checks for `tv.V == nil` first. <details><summary>Contributors' checklist...</summary> - [x] Added new tests, or not needed, or not feasible - [x] Provided an example (e.g. screenshot) to aid review or the PR is self-explanatory - [x] Updated the official documentation or not needed - [x] No breaking changes were made, or a `BREAKING CHANGE: xxx` message was included in the description - [x] Added references to related issues and PRs - [x] Provided any useful hints for running manual tests - [ ] Added new benchmarks to [generated graphs](https://gnoland.github.io/benchmarks), if any. More info [here](https://github.com/gnolang/gno/blob/master/.benchmarks/README.md). </details> --------- Co-authored-by: Manfred Touron <[email protected]>
- Loading branch information