wasm: emit a clean error for scalar ?T/!T returns instead of an internal ICE - #27516
Merged
medvednikov merged 1 commit intoJun 26, 2026
Merged
Conversation
…nternal ICE
A function returning a scalar option/result (e.g. `fn f() ?int`) reaches the
`else` arm of `fn_decl`'s return-type match and calls `get_wasm_type` on the
option/result-wrapped type, which aborts with an internal
`get_wasm_type: unreachable type 'int' ast.TypeInfo(ast.UnknownTypeInfo{})`
instead of the intended located "option/result types are not implemented" user
error. The existing guards only run inside the MultiReturn arm, after the match
(result), or for the void-option case, so they were dead code for a scalar
`?T`/`!T` return.
Guard option/result before lowering the type in the non-void scalar arm. The
void-option case still reports "returning a void option is forbidden".
Adds vlib/v/gen/wasm/tests/scalar_option_result_error_test.v.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
On the native wasm backend, a function returning a scalar option/result (e.g.
fn f() ?int) aborts the compiler with an internal ICE instead of the intended user-facing error:Root cause
In
fn_decl(vlib/v/gen/wasm/gen.v), the return-typematch rts.infohandles option/result only:MultiReturnarm (option types are not implemented),result types are not implemented),returning a void option is forbidden).A scalar
?T/!Treturn is not aMultiReturn, so it falls into theelsearm and callsget_wasm_type(rt)on the option/result-wrapped type before any guard runs — and that aborts with theunreachable type ... UnknownTypeInfoICE. The existing guards were effectively dead code for this case.Fix
Guard option/result in the non-void scalar arm, before lowering the type.
g.v_erroralready exits, so this short-circuits beforeget_wasm_type.After
fn f() !int→result types are not implemented(located).fn f() ?(void option) → stillreturning a void option is forbidden(unchanged).This is in the spirit of #27451 (replace internal
get_wasm_typeICEs with clean errors), covering the scalar option/result cases specifically.Tests
Adds
vlib/v/gen/wasm/tests/scalar_option_result_error_test.v(asserts the located error is produced and the internal ICE string does not leak). Fullvlib/v/gen/wasm/tests/suite passes;v fmtclean.Checklist
v test vlib/v/gen/wasm/tests/)v fmt -wapplied