vxx2 / vlib / v / checker / tests / fn_signature_alias_payload_mismatch_err.vv
20 lines · 16 sloc · 729 bytes · b0e0a1e9348ec11888beaaa21ea9f7ff6eeea0c4
Raw
1// Function-pointer signatures should NOT match across alias-equivalent
2// result/option payloads, because the `_result_*` / `_option_*` C wrapper
3// structs are distinct types — the conversion path used for `return some_call()`
4// (#27264) doesn't run at the fn-signature boundary, so accepting these would
5// pass V checking and then emit incompatible C function-pointer ABI.
6
7type Token = string
8type Tokens = []string
9
10type ReturnsTokens = fn () !Tokens
11
12fn returns_array_of_token() ![]Token {
13 return [Token('hi')]
14}
15
16fn main() {
17 // Without `unsafe`, this must error: `fn () ![]Token` is *not* assignable
18 // to `fn () !Tokens` even though the payloads have the same layout.
19 _ := ReturnsTokens(returns_array_of_token)
20}
21