-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(gnolang): allow comparisons using uninitialized string values #1132
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
thehowl
added
🐞 bug
Something isn't working
📦 🤖 gnovm
Issues or PRs gnovm related
labels
Sep 16, 2023
moul
approved these changes
Sep 16, 2023
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## master #1132 +/- ##
==========================================
+ Coverage 47.31% 47.33% +0.01%
==========================================
Files 367 367
Lines 62118 62118
==========================================
+ Hits 29394 29402 +8
Misses 30325 30325
+ Partials 2399 2391 -8
☔ View full report in Codecov by Sentry. |
Codecov will mark this as not tested without #1122 . I'd say this is still good to merge, though. (Moved to review meeting col) |
zivkovicmilos
approved these changes
Oct 5, 2023
gfanton
pushed a commit
to gfanton/gno
that referenced
this pull request
Nov 9, 2023
…olang#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: gnolang@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 <94029+moul@users.noreply.github.com>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
The provided additional test, without the patch, fails with the following error:
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 useGetString
instead of a type assertion ofTypedValue.V
to aStringValue
. This is in line with what is already done inside ofisEql
, 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 ofappend
. 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 asGetString()
internally just does the type assertion, but checks fortv.V == nil
first.Contributors' checklist...
BREAKING CHANGE: xxx
message was included in the description