Skip to content

Commit

Permalink
feat: improve panic error
Browse files Browse the repository at this point in the history
  • Loading branch information
omarsy committed May 11, 2024
1 parent f03a63e commit 28add6c
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/preprocess.go
Original file line number Diff line number Diff line change
Expand Up @@ -896,7 +896,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in binary expression: %v %v %v",
n.Left, n.Op, n.Right))
lt.TypeID(), n.Op, rt.TypeID()))
}
pt := go2GnoBaseType(lnt.Type).(PrimitiveType)
// convert n.Left to (gno) pt type,
Expand Down Expand Up @@ -935,7 +935,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in binary expression: %v %v %v",
n.Left, n.Op, n.Right))
lt.TypeID(), n.Op, rt.TypeID()))
}
} else {
checkOrConvertType(store, last, &n.Left, rt, false)
Expand All @@ -948,7 +948,7 @@ func Preprocess(store Store, ctx BlockNode, n Node) Node {
if lt.TypeID() != rt.TypeID() {
panic(fmt.Sprintf(
"incompatible types in binary expression: %v %v %v",
n.Left, n.Op, n.Right))
lt.TypeID(), n.Op, rt.TypeID()))
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions gnovm/pkg/gnolang/preprocess_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ func TestPrepocessBinaryExpressionPrimaryAndNative(t *testing.T) {
import "time"
func main() {
var a int64 = 2
println(a * time.Second)
println(time.Second * a)
}`
n := MustParseFile("main.go", c)
assert.Panics(t, func() { m.RunFiles(n) }, "should panic: invalid operation: int64 * time.Duration")
assert.Panics(t, func() { m.RunFiles(n) })
}

func TestPrepocessBinaryExpressionNativeAndNative(t *testing.T) {
Expand Down Expand Up @@ -62,5 +62,5 @@ func main() {
}`
n := MustParseFile("main.go", c)
assert.Panics(t, func() { m.RunFiles(n) }, "should panic: invalid operation: time.Month * time.Weekday")
assert.Panics(t, func() { m.RunFiles(n) })
}
2 changes: 1 addition & 1 deletion gnovm/tests/files/time16_native.gno
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ func main() {
}

// Error:
// main/files/time16_native.gno:10: incompatible types in binary expression: time<VPBlock(2,1)>.Second MUL a<VPBlock(1,0)>
// main/files/time16_native.gno:10: incompatible types in binary expression: go:time.Duration MUL int64

0 comments on commit 28add6c

Please sign in to comment.