Skip to content

Type alias in struct copy causes compiler to crash #24581

@mike-ward

Description

@mike-ward

Describe the bug

Using a type alias as follows crashes the compiler

Reproduction Steps

module main

struct Cfg {
	item string
}

type AliasCfg = Cfg

fn foo(cfg &AliasCfg) {
	mut acfg := &AliasCfg{
		...cfg
	}
}

fn main() {
}

v run .

Expected Behavior

Should not crash

Current Behavior

V panic: as cast: cannot cast `v.ast.Alias` to `v.ast.Struct`
v hash: 52c7130
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:19800: at _v_panic: Backtrace
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:20274: by __as_cast
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:70939: by v__checker__Checker_struct_init
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:54393: by v__checker__Checker_expr
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:48689: by v__checker__Checker_assign_stmt
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:52889: by v__checker__Checker_stmt
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:53507: by v__checker__Checker_stmts_ending_with_expression
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:53484: by v__checker__Checker_stmts
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:61304: by v__checker__Checker_fn_decl
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:52937: by v__checker__Checker_stmt
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:50826: by v__checker__Checker_check
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:50889: by v__checker__Checker_check_files
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:116133: by v__builder__Builder_middle_stages
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:116171: by v__builder__Builder_front_and_middle_stages
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:118771: by v__builder__cbuilder__gen_c
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:118743: by v__builder__cbuilder__build_c
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:118734: by v__builder__cbuilder__compile_c
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:118651: by v__builder__Builder_rebuild
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:117804: by v__builder__compile
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:119169: by main__rebuild
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:119085: by main__main
v2.01JW401TWHRN7D237PB6SD54CR.tmp.c:119946: by main

Possible Solution

None

Additional Information/Context

No response

V version

V 0.4.10 52c7130

Environment details (OS name and version, etc.)

V full version V 0.4.10 da3112e.52c7130
OS macos, macOS, 15.5, 24F74
Processor 8 cpus, 64bit, little endian, Apple M2
Memory 0.16GB/8GB
V executable /Users/mike/Documents/github/v/v
V last modified time 2025-05-25 15:12:48
V home dir OK, value: /Users/mike/Documents/github/v
VMODULES OK, value: /Users/mike/.vmodules
VTMP OK, value: /tmp/v_501
Current working dir OK, value: /Users/mike/Documents/github/bug
env VFLAGS "-path /Users/mike/Documents/github
Git version git version 2.49.0
V git status weekly.2025.17-161-g52c7130a
.git/config present true
cc version Apple clang version 17.0.0 (clang-1700.0.13.3)
gcc version Apple clang version 17.0.0 (clang-1700.0.13.3)
clang version Apple clang version 17.0.0 (clang-1700.0.13.3)
tcc version tcc version 0.9.28rc 2024-02-05 HEAD@105d70f7 (AArch64 Darwin)
tcc git status thirdparty-macos-arm64 c8df4e27
emcc version N/A
glibc version N/A

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

Labels

BugThis tag is applied to issues which reports bugs.Status: ConfirmedThis bug has been confirmed to be valid by a contributor.Unit: CheckerBugs/feature requests, that are related to the type checker.

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions