diff options
-rw-r--r-- | errors_test.go | 1 | ||||
-rw-r--r-- | interp/interpreter.go | 4 | ||||
-rw-r--r-- | testdata/errors/interp.go | 31 |
3 files changed, 36 insertions, 0 deletions
diff --git a/errors_test.go b/errors_test.go index 49d7b2573..d671e7335 100644 --- a/errors_test.go +++ b/errors_test.go @@ -17,6 +17,7 @@ import ( func TestErrors(t *testing.T) { for _, name := range []string{ "cgo", + "interp", "loader-importcycle", "loader-invaliddep", "loader-invalidpackage", diff --git a/interp/interpreter.go b/interp/interpreter.go index ea5eeaa12..b35129b81 100644 --- a/interp/interpreter.go +++ b/interp/interpreter.go @@ -417,6 +417,10 @@ func (r *runner) run(fn *function, params []value, parentMem *memoryView, indent } else { locals[inst.localIndex] = literalValue{uint8(0)} } + case callFn.name == "__tinygo_interp_raise_test_error": + // Special function that will trigger an error. + // This is used to test error reporting. + return nil, mem, r.errorAt(inst, errors.New("test error")) case strings.HasSuffix(callFn.name, ".$typeassert"): if r.debug { fmt.Fprintln(os.Stderr, indent+"interface assert:", operands[1:]) diff --git a/testdata/errors/interp.go b/testdata/errors/interp.go new file mode 100644 index 000000000..a3f5cee78 --- /dev/null +++ b/testdata/errors/interp.go @@ -0,0 +1,31 @@ +package main + +import _ "unsafe" + +func init() { + foo() +} + +func foo() { + interp_test_error() +} + +// This is a function that always causes an error in interp, for testing. +// +//go:linkname interp_test_error __tinygo_interp_raise_test_error +func interp_test_error() + +func main() { +} + +// ERROR: # main +// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:10:19: test error +// ERROR: call void @__tinygo_interp_raise_test_error{{.*}} +// ERROR: {{}} +// ERROR: traceback: +// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:10:19: +// ERROR: call void @__tinygo_interp_raise_test_error{{.*}} +// ERROR: {{.*testdata[\\/]errors[\\/]interp\.go}}:6:5: +// ERROR: call void @main.foo{{.*}} +// ERROR: {{.*testdata[\\/]errors}}: +// ERROR: call void @"main.init#1"{{.*}} |