Skip to content

Commit 1a99094

Browse files
authored
fix(gnovm): fix unary operator ^ on constants (#3876)
Apply Bigint.Not for untyped big ints. Fixes #3864.
1 parent 253c766 commit 1a99094

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

gnovm/pkg/gnolang/op_unary.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ func (m *Machine) doOpUxor() {
113113
case Uint64Type:
114114
xv.SetUint64(^xv.GetUint64())
115115
case UntypedBigintType:
116-
// XXX can it even be implemented?
117-
panic("not yet implemented")
116+
bv := xv.V.(BigintValue)
117+
xv.V = BigintValue{V: new(big.Int).Not(bv.V)}
118118
default:
119119
panic(fmt.Sprintf("unexpected type %s in operation",
120120
baseOf(xv.T)))

gnovm/tests/files/const59.gno

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package main
2+
3+
const (
4+
A = ^0
5+
B = ^1
6+
C = int8(^1)
7+
D = ^uint8(1)
8+
)
9+
10+
func main() {
11+
println(A, B, C, D)
12+
}
13+
14+
// Output:
15+
// -1 -2 -2 254

gnovm/tests/files/const60.gno

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
const (
4+
A = uint(^1)
5+
)
6+
7+
func main() {
8+
println(A)
9+
}
10+
11+
// Error:
12+
// main/files/const60.gno:4:6: bigint underflows target kind

gnovm/tests/files/const61.gno

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main
2+
3+
const (
4+
A = uint8(^0)
5+
)
6+
7+
func main() {
8+
println(A)
9+
}
10+
11+
// Error:
12+
// main/files/const61.gno:4:6: bigint underflows target kind

0 commit comments

Comments
 (0)