cx icon indicating copy to clipboard operation
cx copied to clipboard

Runtime error when calling str.i32 with a string not representing a valid i32 number.

Open vidya88 opened this issue 5 years ago • 2 comments

@asahi3g commented on Jul 3

To Reproduce

package main
func main()() {
	i := str.i32("a")
	k := str.i32("-2147483649")
}

Expected behavior Parsing methods (str.*) should return an error on failure.

Screenshots

error: pending_12.cx:4, CX_RUNTIME_ERROR, 
===Callstack===
>>> main()
Expressions
 	pending_12.cx:4 : str.i32() : 0
	pending_12.cx:5 : str.i32() : 0

goroutine 1 [running, locked to thread]:
runtime/debug.Stack(0x2a, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/skycoin/cx/cx.runtimeErrorInfo(0xcece40, 0xfb2cf0, 0xfb2c01, 0x5)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:836 +0x2c1
github.com/skycoin/cx/cx.RuntimeError()
	/home/cxfx/go/src/github.com/skycoin/cx/cx/utilities.go:859 +0x16d
panic(0xcece40, 0xfb2cf0)
	/usr/local/go/src/runtime/panic.go:522 +0x1b5
github.com/skycoin/cx/cx.opStrStr(0xc0000928c0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/op_str.go:27 +0x4d1
github.com/skycoin/cx/cx.init.2.func1(0xc00019c0f0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_core.go:1302 +0x6dd
github.com/skycoin/cx/cx.init.3.func1(0xc00019c0f0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/opcodes_extra.go:594 +0xfc3
github.com/skycoin/cx/cx.(*CXCall).ccall(0xc0002ea000, 0xc00019c0f0, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:278 +0x331
github.com/skycoin/cx/cx.(*CXProgram).Run(0xc00019c0f0, 0xe3ef01, 0xc000199250, 0xffffffffffffffff, 0x0, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:118 +0x126
github.com/skycoin/cx/cx.(*CXProgram).RunCompiled(0xc00019c0f0, 0x0, 0x0, 0x0, 0x0, 0xc000080750, 0x0)
	/home/cxfx/go/src/github.com/skycoin/cx/cx/execute.go:200 +0x231
main.main()
	/home/cxfx/go/src/github.com/skycoin/cx/cxgo/main.go:1003 +0x24c3

Desktop:

  • OS: Linux
  • CX Version 0.0.7, commit: f999780

vidya88 avatar Sep 24 '19 01:09 vidya88

@arfan499 Make a unit test for this ticket. Then comment back here.

SkycoinSynth avatar Feb 04 '21 10:02 SkycoinSynth

Two issues

1> Should return error instead of crashing

2> If string is literal, then should be converted at compile time and not run time?

SkycoinSynth avatar Feb 04 '21 10:02 SkycoinSynth