Skip to content
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
merged 7 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gnovm/pkg/gnolang/op_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func isEql(store Store, lv, rv *TypedValue) bool {
func isLss(lv, rv *TypedValue) bool {
switch lv.T.Kind() {
case StringKind:
return (lv.V.(StringValue) < rv.V.(StringValue))
return (lv.GetString() < rv.GetString())
case IntKind:
return (lv.GetInt() < rv.GetInt())
case Int8Kind:
Expand Down Expand Up @@ -533,7 +533,7 @@ func isLss(lv, rv *TypedValue) bool {
func isLeq(lv, rv *TypedValue) bool {
switch lv.T.Kind() {
case StringKind:
return (lv.V.(StringValue) <= rv.V.(StringValue))
return (lv.GetString() <= rv.GetString())
case IntKind:
return (lv.GetInt() <= rv.GetInt())
case Int8Kind:
Expand Down Expand Up @@ -577,7 +577,7 @@ func isLeq(lv, rv *TypedValue) bool {
func isGtr(lv, rv *TypedValue) bool {
switch lv.T.Kind() {
case StringKind:
return (lv.V.(StringValue) > rv.V.(StringValue))
return (lv.GetString() > rv.GetString())
case IntKind:
return (lv.GetInt() > rv.GetInt())
case Int8Kind:
Expand Down Expand Up @@ -621,7 +621,7 @@ func isGtr(lv, rv *TypedValue) bool {
func isGeq(lv, rv *TypedValue) bool {
switch lv.T.Kind() {
case StringKind:
return (lv.V.(StringValue) >= rv.V.(StringValue))
return (lv.GetString() >= rv.GetString())
case IntKind:
return (lv.GetInt() >= rv.GetInt())
case Int8Kind:
Expand Down
2 changes: 1 addition & 1 deletion gnovm/pkg/gnolang/uverse.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ func UverseNode() *PackageNode {
if xt.Elem().Kind() == Uint8Kind {
// TODO this might be faster if reflect supports
// appending this way without first converting to a slice.
argrv := reflect.ValueOf([]byte(arg1.TV.V.(StringValue)))
argrv := reflect.ValueOf([]byte(arg1.TV.GetString()))
resrv := reflect.AppendSlice(sv, argrv)
m.PushValue(TypedValue{
T: xt,
Expand Down
10 changes: 10 additions & 0 deletions gnovm/tests/files/append5.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package main

func main() {
var x string
y := append([]byte{'X'}, x...)
println(string(y))
}

// Output:
// X
21 changes: 21 additions & 0 deletions gnovm/tests/files/comp3.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package main

func main() {
// test against uninitialized value: https://github.com/gnolang/gno/pull/1132
var x string
y := "Hello"
results := [...]bool{
x < y,
x <= y,
x >= y,
x > y,

x == y,
x == "",
y == "",
}
println(results)
}

// Output:
// array[(true bool),(true bool),(false bool),(false bool),(false bool),(true bool),(false bool)]