Skip to content

[type]: array type aliases don't work #27006

@CryingN

Description

@CryingN

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:

module v_llama_cpp

pub type Token = string
pub type Tokens = []string

pub fn test(data Tokens) {
    println(data)
}

test.v:

module main

import v_llama_cpp

fn main() {
    token := "data1"
    mut tokens := []v_llama_cpp.Token{}
    tokens << token
    v_llama_cpp.test(tokens)
}

Expected Behavior

v_llama_cpp.Tokens(['data1'])

Current Behavior

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 |     mut tokens := []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

Environment details (OS name and version, etc.)

[root_cn@archlinux test]$ v doctor

V full version V 0.5.1 defdc5e
OS linux, Linux version 6.19.11-arch1-1 (linux@archlinux) (gcc (GCC) 15.2.1 20260209, GNU ld (GNU Binutils) 2.46) #1 SMP PREEMPT_DYNAMIC Thu, 02 Apr 2026 23:33:01 +0000
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8265U CPU @ 1.60GHz
Memory 1.13GB/7.51GB
V executable /home/root_cn/work/vlang/v/v
V last modified time 2026-04-27 07:06:52
V home dir OK, value: /home/root_cn/work/vlang/v
VMODULES OK, value: /home/root_cn/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/root_cn/work/vlang/test
Git version git version 2.54.0
V git status defdc5e
.git/config present true
cc version cc (GCC) 15.2.1 20260209
gcc version gcc (GCC) 15.2.1 20260209
clang version clang version 22.1.3
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (GNU libc) 2.43

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions