Skip to content

Commit

Permalink
fix: prevent assignment to native type
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed Oct 2, 2024
1 parent fa45914 commit 0563a00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -2031,6 +2031,10 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
// General case: a, b = x, y.
for i, lx := range n.Lhs {
lt := evalStaticTypeOf(store, last, lx)
if _, ok := lt.(*NativeType); ok {
panic("assignment to native type is not permitted")
}

// if lt is interface, nothing will happen
checkOrConvertType(store, last, &n.Rhs[i], lt, true)
}
Expand Down
12 changes: 12 additions & 0 deletions gnovm/tests/files/assign29_native.gno
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package main

import "time"

func main() {
time.Now = func() time.Time {
return time.Time{}
}
}

// Error:
// main/files/assign29_native.gno:6:2: assignment to native type is not permitted

0 comments on commit 0563a00

Please sign in to comment.