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: untyped values use calling builtin function's type #1423

Merged
merged 6 commits into from
Jan 11, 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
10 changes: 9 additions & 1 deletion gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
}
n.NumArgs = 1
if arg0, ok := n.Args[0].(*ConstExpr); ok {
var constConverted bool
ct := evalStaticType(store, last, n.Func)
// As a special case, if a decimal cannot
// be represented as an integer, it cannot be converted to one,
Expand All @@ -967,10 +968,17 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
arg0))
}
}
deelawn marked this conversation as resolved.
Show resolved Hide resolved

convertConst(store, last, arg0, ct)
constConverted = true
}

// (const) untyped decimal -> float64.
// (const) untyped bigint -> int.
convertConst(store, last, arg0, nil)
if !constConverted {
convertConst(store, last, arg0, nil)
}

// evaluate the new expression.
cx := evalConst(store, last, n)
// Though cx may be undefined if ct is interface,
Expand Down
20 changes: 20 additions & 0 deletions gnovm/tests/files/issue-1085.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package main

func main() {
a := uint64(9223372036854775808)
var b uint64 = uint64(9223372036854775808)

const c = uint64(9223372036854775808)
const d uint64 = uint64(9223372036854775808)

println(a)
println(b)
println(c)
println(d)
}

// Output:
// 9223372036854775808
// 9223372036854775808
// 9223372036854775808
// 9223372036854775808
Loading