Skip to content

ORM or veb or json: C error #24242

@Avey777

Description

@Avey777

Describe the bug

Using optional time field, c error

Reproduction Steps

module main

import veb
import db.mysql
import time
import orm

@[table: 'sys_users']
struct User {
pub:
	id         string     @[immutable; primary; sql: 'id'; sql_type: 'VARCHAR(255)'; unique]
	name       string    @[immutable; sql: 'username'; sql_type: 'VARCHAR(255)'; unique]
	created_at ?time.Time @[omitempty; sql_type: 'TIMESTAMP']
	updated_at time.Time  @[omitempty; sql_type: 'TIMESTAMP']
}

struct Context {
	veb.Context
}

struct App {
	veb.Middleware[Context]
}

fn main() {
	port := 9009
	mut app := &App{}
	veb.run[App, Context](mut app, port)
}

@['/'; get]
fn (app &App) index(mut ctx Context) !veb.Result {
	mut pool := db_pool()
	defer { pool.close() }

	mut pb := pool.acquire()!
	defer { pool.release(pb) }
	dump(pb)

	mut result0 := sql pb {
		select from User
	}!
	dump(result0)

	mut qb := orm.new_query[User](pb)
	result := qb.select()!.query()!
	dump(result)

	return ctx.json(result)
}

fn db_pool() mysql.ConnectionPool {
	config := mysql.Config{
		host:     'mysql2.sqlpub.com'
		port:     3307
		username: 'vcore_test'
		password: 'wfo8wS7CylT0qIMg'
		dbname:   'vcore_test'
	}

	mut pool := mysql.new_connection_pool(config, 10) or { panic('Failed to create pool: ${err}') }
	dump(pool)

	return pool
}

The code can be run directly, and the database configuration can be used directly

Expected Behavior

no error

Current Behavior

================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/temp.01JRY5XY4AYEMKMPKGECCQH77F.tmp.c:8414: error: cannot convert 'struct time__Time' to 'struct _option_time__Time'
=================================================================
(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

================== C compilation error (from tcc): ============== cc: /tmp/v_1000/temp.01JRY5XY4AYEMKMPKGECCQH77F.tmp.c:8414: error: cannot convert 'struct time__Time' to 'struct _option_time__Time' ================================================================= (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 .

Environment details (OS name and version, etc.)

V full version V 0.4.10 86536e4.e972860
OS linux, Deepin 23
Processor 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory 0.31GB/7.61GB
V executable /home/Jengro/.vmr/versions/v_versions/v_latest/v
V last modified time 2025-04-16 00:05:45
V home dir OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest
VMODULES OK, value: /home/Jengro/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/Jengro/Documents/Dev/v-product/vprod-workspase/example
Git version git version 2.45.2
V git status weekly.2025.14-51-ge972860f
.git/config present true
cc version cc (Deepin 12.3.0-17deepin8) 12.3.0
gcc version gcc (Deepin 12.3.0-17deepin8) 12.3.0
clang version Deepin clang version 17.0.6 (5deepin5)
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 (Debian GLIBC 2.38-6deepin7) 2.38

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