Skip to content

bug: c_string() does not validate argument is a pointer type #1575

@SchoolyB

Description

@SchoolyB

Description

c_string() does not validate its argument type. Passing an EZ string literal (or any non-pointer value) bypasses the typechecker and produces a C compilation error:

operand of type 'EzString' where arithmetic or pointer type is required

Users should never see C compiler errors.

Repro

do main() {
    mut msg = c_string("hello")
    println(msg)
}

Expected: Typechecker error — c_string() expects a raw pointer from C interop.

Actual: Falls through to codegen and fails at C compilation.

Root cause

In typechecker.c, c_string is recognized and its return type is set to string, but there's no check that the argument is a pointer type (TK_POINTER). The codegen wraps the EZ string in ez_string_lit() and tries to cast it to const char*, which fails at the C level.

Fix

Add a type check in the typechecker's c_string handler — verify the argument resolves to a pointer type. If not, emit E3083.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingtypecheckerRelated to type checking and validation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions