Skip to content

$match assignment will crash compiler #26053

Description

@kbkpbot

Describe the bug

Assignment with $match will cause compiler panic.

Reproduction Steps

match.v

module main

import strconv

fn ret[T](str string) !T {
        val := $match T.unaliased_typ {
                i8 { strconv.atoi8(str)! }
                i16 { strconv.atoi16(str)! }
                i32 { strconv.atoi32(str)! }
                i64 { strconv.atoi64(str)! }
                u8 { strconv.atou8(str)! }
                u16 { strconv.atou16(str)! }
                u32 { strconv.atou32(str)! }
                u64 { strconv.atou64(str)! }
                int { strconv.atoi(str)! }
                $float { T(strconv.atof_quick(str)) }
                $else { return error('`decode_number` can not decode ${T.name} type') }
        }
        return val
}

fn main() {
        x := ret[f32]('1.0')!
        dump(x)
}
v match.v

Expected Behavior

compile ok or report error/warnings

Current Behavior

$ v match.v
V panic: table.sym: invalid type (typ=ast.Type(0x0 = 0) idx=0). Compiler bug. This should never happen. Please report the bug using `v bug file.v`.

 v hash: fd31771
    pid: 0x3ce22
    tid: 0x3ce22
/tmp/v_1000/v2.tmp.c:21745: at builtin___v_panic: Backtrace
/tmp/v_1000/v2.tmp.c:37908: by v__ast__default_table_panic_handler
/tmp/v_1000/v2.tmp.c:37914: by v__ast__Table_panic
/tmp/v_1000/v2.tmp.c:38616: by v__ast__Table_sym
/tmp/v_1000/v2.tmp.c:5954: by v__checker__Checker_match_expr
/tmp/v_1000/v2.tmp.c:56723: by v__checker__Checker_expr
/tmp/v_1000/v2.tmp.c:50308: by v__checker__Checker_assign_stmt
/tmp/v_1000/v2.tmp.c:55442: by v__checker__Checker_stmt
/tmp/v_1000/v2.tmp.c:56078: by v__checker__Checker_stmts_ending_with_expression
/tmp/v_1000/v2.tmp.c:56055: by v__checker__Checker_stmts
/tmp/v_1000/v2.tmp.c:64893: by v__checker__Checker_fn_decl
/tmp/v_1000/v2.tmp.c:1761: by v__checker__Checker_post_process_generic_fns
/tmp/v_1000/v2.tmp.c:53491: by v__checker__Checker_check_files
/tmp/v_1000/v2.tmp.c:56777: by v__builder__Builder_middle_stages
/tmp/v_1000/v2.tmp.c:56818: by v__builder__Builder_front_and_middle_stages
/tmp/v_1000/v2.tmp.c:59342: by v__builder__cbuilder__gen_c
/tmp/v_1000/v2.tmp.c:59314: by v__builder__cbuilder__build_c
/tmp/v_1000/v2.tmp.c:59305: by v__builder__cbuilder__compile_c
/tmp/v_1000/v2.tmp.c:59222: by v__builder__Builder_rebuild
/tmp/v_1000/v2.tmp.c:58368: by v__builder__compile
/tmp/v_1000/v2.tmp.c:59734: by main__rebuild
/tmp/v_1000/v2.tmp.c:59686: by main__main
/tmp/v_1000/v2.tmp.c:60702: by main

Possible Solution

fix checker

Additional Information/Context

No response

V version

V 0.4.12 1cdb0f5.fd31771

Environment details (OS name and version, etc.)

V full version V 0.4.12 1cdb0f5.fd31771
OS linux, Ubuntu 24.04.3 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 9.9GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-12-20 13:56:50
V home dir OK, value: /media/HD/github/kbkpbot/v
VMODULES OK, value: /home/mars/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/mars/v/bug/json
Git version git version 2.43.0
V git status weekly.2025.46-243-gfd317711-dirty
.git/config present true
cc version cc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
gcc version gcc (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0
clang version Ubuntu clang version 18.1.3 (1ubuntu1)
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 (Ubuntu GLIBC 2.39-0ubuntu8.6) 2.39

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.ComptimeFeatures processed during compile time, like $if, $for, $env etc

    Type

    No fields configured for Bug.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions