You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Type alias Tokens = []string cannot accept a variable initialized with []Token{} (where Token = string), even though both have the same underlying type []string. The compiler rejects the assignment with a type mismatch error.
test.v:13:7: error: cannot use `[]v_llama_cpp.Token`as`v_llama_cpp.Tokens`in argument 1 to `v_llama_cpp.test`11|muttokens:= []Token{}
12| tokens << token
13|test(tokens)
|~~~~~~14| }
15|
Possible Solution
When checking type compatibility, recursively resolve all type aliases to their fundamental types first, then compare. This aligns with the Principle of Least Astonishment and matches behavior in other statically-typed languages with type aliases. This way both []Token and Tokens normalize to []string and become compatible.
Additional Information/Context
No response
V version
[root_cn@archlinux test]$ v --version V 0.5.1 defdc5e
Describe the bug
Type alias Tokens = []string cannot accept a variable initialized with []Token{} (where Token = string), even though both have the same underlying type []string. The compiler rejects the assignment with a type mismatch error.
Reproduction Steps
v_llama_cpp/type.v:test.v:Expected Behavior
Current Behavior
Possible Solution
When checking type compatibility, recursively resolve all type aliases to their fundamental types first, then compare. This aligns with the Principle of Least Astonishment and matches behavior in other statically-typed languages with type aliases. This way both
[]TokenandTokensnormalize to[]stringand become compatible.Additional Information/Context
No response
V version
[root_cn@archlinux test]$ v --version V 0.5.1 defdc5e
Environment details (OS name and version, etc.)
[root_cn@archlinux test]$ v doctor
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.