Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect typecheck in sql expressions #20699

Open
koplenov opened this issue Feb 1, 2024 · 1 comment · May be fixed by #21174
Open

Incorrect typecheck in sql expressions #20699

koplenov opened this issue Feb 1, 2024 · 1 comment · May be fixed by #21174
Labels
ORM Bugs/feature requests, that are related to the V ORM.

Comments

@koplenov
Copy link
Contributor

koplenov commented Feb 1, 2024

V doctor:

V full version: V 0.4.4 cae40ad
OS: linux, Debian GNU/Linux 12 (bookworm)
Processor: 4 cpus, 64bit, little endian, Intel(R) Core(TM) i5-3337U CPU @ 1.80GHz

getwd: /home/koplenov/dev/zone/cjer
vexe: /home/koplenov/dev/v/v
vexe mtime: 2024-01-29 11:59:16

vroot: OK, value: /home/koplenov/dev/v
VMODULES: OK, value: /home/koplenov/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.2
Git vroot status: Error: fatal: не найден git репозиторий (или один из родительских каталогов): .git
.git/config present: false

CC version: cc (Debian 12.2.0-14) 12.2.0
thirdparty/tcc: N/A

What did you do?
v -g -o vdbg cmd/v && vdbg sql_bug.v

module main

import db.sqlite

pub struct SeoBlock {
    pub:
    seo_f1 string
    seo_is_f1_capitalize bool
    seo_params string
}

fn main() {
	db := sqlite.connect('test.db') or { panic(err) }

    sql db {
        update SeoBlock set seo_f1 = seo_f1 where seo_f1 == ""
    } or { panic(err) }
}

What did you expect to see?

Correct error in sql expression

What did you see instead?

================ V panic ================
   module: v.ast
 function: default_table_panic_handler()
  message: 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`.

     file: /home/koplenov/dev/v/vlib/v/ast/table.v:85
   v hash: cae40ad
=========================================
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/builtin/builtin.c.v:66: at panic_debug: Backtrace
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/ast/table.v:85: by v__ast__default_table_panic_handler
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/ast/table.v:91: by v__ast__Table_panic
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/ast/table.v:679: by v__ast__Table_sym
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/orm.v:527: by v__gen__c__Gen_write_orm_primitive
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/orm.v:506: by v__gen__c__Gen_write_orm_expr_to_primitive
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/orm.v:244: by v__gen__c__Gen_write_orm_update
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/orm.v:88: by v__gen__c__Gen_sql_stmt_line
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/orm.v:63: by v__gen__c__Gen_sql_stmt
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:2212: by v__gen__c__Gen_stmt
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:1884: by v__gen__c__Gen_stmts_with_tmp_var
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:1771: by v__gen__c__Gen_stmts
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/fn.v:408: by v__gen__c__Gen_gen_fn_decl
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/fn.v:111: by v__gen__c__Gen_fn_decl
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:2120: by v__gen__c__Gen_stmt
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:1884: by v__gen__c__Gen_stmts_with_tmp_var
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:1771: by v__gen__c__Gen_stmts
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:748: by v__gen__c__Gen_gen_file
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/v/gen/c/cgen.v:698: by v__gen__c__cgen_process_one_file_cb
/tmp/v_1000/../../../../../../home/koplenov/dev/v/vlib/sync/pool/pool.c.v:117: by sync__pool__process_in_thread
/tmp/v_1000/vdbg.01HNJAQWADAG0NH11PNHMQCVJ7.tmp.c:11408: by sync__pool__process_in_thread_thread_wrapper
7fb044020044 : by ???

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.

@viniciusfdasilva
Copy link
Contributor

@koplenov This error occurs because the value that V considers after the '=' in the case 'seo_f1' is seen as an identifier belonging to the language, not a possible value of the table field. It is indeed a bug in the language. The example below shows a way the language recognizes it.

import db.sqlite

pub struct SeoBlock {
    
    seo_f1 string
    seo_is_f1_capitalize bool
    seo_params string
}

fn main() {
	db := sqlite.connect('test.db') or { panic(err) }

	t := SeoBlock{'test1',true,'test'}
	local_seo_f1 := 'test2'
	
    sql db {
	create table SeoBlock
        update SeoBlock set seo_f1 = t.seo_f1 where seo_f1 == ""
	update SeoBlock set seo_f1 = local_seo_f1 where seo_f1 == ""
    } or { panic(err) }
}

@felipensp felipensp added the ORM Bugs/feature requests, that are related to the V ORM. label Feb 13, 2024
@Delta456 Delta456 linked a pull request Apr 3, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ORM Bugs/feature requests, that are related to the V ORM.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants