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: []byte("xxx") should not be treated as const #1597

Merged
merged 4 commits into from
Feb 14, 2024
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
7 changes: 5 additions & 2 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -978,11 +978,14 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
arg0))
}
}

convertConst(store, last, arg0, ct)
constConverted = true
case SliceKind:
if ct.Elem().Kind() == Uint8Kind { // bypass []byte("xxx")
n.SetAttribute(ATTR_TYPEOF_VALUE, ct)
return n, TRANS_CONTINUE
}
}

// (const) untyped decimal -> float64.
// (const) untyped bigint -> int.
if !constConverted {
Expand Down
15 changes: 15 additions & 0 deletions gnovm/tests/files/byte_slice_issue1570.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package main

func main() {
for i := 0; i < 2; i++ {
l := []byte("lead")
if i == 0 {
l[0] = 'f'
}
println(string(l))
}
}

// Output:
// fead
// lead
Loading