|
| 1 | +import os |
| 2 | + |
| 3 | +// A scalar `?T`/`!T` return type used to abort the wasm backend with an internal |
| 4 | +// `get_wasm_type: unreachable type ... UnknownTypeInfo` ICE, because the |
| 5 | +// option/result guards only ran inside the MultiReturn arm / after the type was |
| 6 | +// already lowered. The backend must instead emit the intended, located |
| 7 | +// "not implemented" user error. |
| 8 | +fn compile_wasm(src string, name string) os.Result { |
| 9 | + vexe := os.quoted_path(@VEXE) |
| 10 | + wrkdir := os.join_path(os.vtmp_dir(), 'wasm_scalar_optres_tests') |
| 11 | + os.mkdir_all(wrkdir) or { panic(err) } |
| 12 | + source_path := os.join_path(wrkdir, '${name}.v') |
| 13 | + output_path := os.join_path(wrkdir, '${name}.wasm') |
| 14 | + os.write_file(source_path, src) or { panic(err) } |
| 15 | + return os.execute('${vexe} -b wasm -o ${os.quoted_path(output_path)} ${os.quoted_path(source_path)}') |
| 16 | +} |
| 17 | + |
| 18 | +fn test_scalar_option_return_errors_cleanly() { |
| 19 | + res := compile_wasm('fn f() ?int {\n\treturn 3\n}\n\nfn main() {\n\tx := f() or { 0 }\n\t_ = x\n}\n', |
| 20 | + 'scalar_option') |
| 21 | + assert res.exit_code != 0, 'expected a compile error, got: ${res.output}' |
| 22 | + assert res.output.contains('option types are not implemented'), res.output |
| 23 | + assert !res.output.contains('get_wasm_type: unreachable'), 'leaked the internal ICE: ${res.output}' |
| 24 | +} |
| 25 | + |
| 26 | +fn test_scalar_result_return_errors_cleanly() { |
| 27 | + res := compile_wasm('fn f() !int {\n\treturn 3\n}\n\nfn main() {\n\tx := f() or { 0 }\n\t_ = x\n}\n', |
| 28 | + 'scalar_result') |
| 29 | + assert res.exit_code != 0, 'expected a compile error, got: ${res.output}' |
| 30 | + assert res.output.contains('result types are not implemented'), res.output |
| 31 | + assert !res.output.contains('get_wasm_type: unreachable'), 'leaked the internal ICE: ${res.output}' |
| 32 | +} |
0 commit comments