Skip to content

[orm] C error while field default value include "" #24052

Description

@kbkpbot

Describe the bug

When create a field with default value include "" in it, it will generate a C error.

Reproduction Steps

o.v

module main

import db.mysql


fn main() {
        db := db_mysql() or { panic('failed to connect to database') }

        sql db {
                create table User
        } or { panic(err) }
}

@[table: 'sys_users']
struct User {
pub:
        home_path ?string @[default: '"dashboard"'; sql_type: 'VARCHAR(64)']   // "dashboard" will compile fail.
}

fn db_mysql() !mysql.DB {

        mut mysql_config := mysql.Config{
                host:     '127.0.0.1'
                port:     3306
                username: 'root'
                password: '12345678'
                dbname:   'vcore'
        }

        mut conn := mysql.connect(mysql_config) or {
                return err
        }

        return conn
}
v o.v

Expected Behavior

compile ok

Current Behavior

$ v o.v
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/o.01JQ9CGNBWZD724RNJ8FXMAJF7.tmp.c:10572: warning: assignment discards qualifiers from pointer target type
cc: /tmp/v_1000/o.01JQ9CGNBWZD724RNJ8FXMAJF7.tmp.c:10612: error: ')' expected (got "dashboard")
...
cc: /tmp/v_1000/o.01JQ9CGNBWZD724RNJ8FXMAJF7.tmp.c:10612: error: ')' expected (got "dashboard")
(note: the original output was 4 lines long; it was truncated to its first 2 lines + the last line)
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.10 bd2ec67.f7f89b3

Environment details (OS name and version, etc.)

V full version V 0.4.10 bd2ec67.f7f89b3
OS linux, Ubuntu 24.04.2 LTS
Processor 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-9700 CPU @ 3.00GHz
Memory 10.83GB/15.51GB
V executable /media/HD/github/kbkpbot/v/v
V last modified time 2025-03-26 13:08:17
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/orm
Git version git version 2.43.0
V git status weekly.2025.13-14-gf7f89b3c-dirty (2 commit(s) behind V master)
.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 2024-07-31 HEAD@1cee0908 (x86_64 Linux)
tcc git status thirdparty-linux-amd64 0134e9b9-dirty
emcc version N/A
glibc version ldd (Ubuntu GLIBC 2.39-0ubuntu8.4) 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

Labels

BugThis tag is applied to issues which reports bugs.

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions