Skip to content

Commit

Permalink
Merge pull request #1 from vlang/master
Browse files Browse the repository at this point in the history
Small cleanup to the `x.encoding.asn1` module
  • Loading branch information
blackshirt authored Nov 13, 2024
2 parents f6942ab + ebb3a8e commit a9e551d
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 2 deletions.
2 changes: 2 additions & 0 deletions cmd/tools/vtest-self.v
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ const skip_with_fsanitize_memory = [
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
'vlib/v/tests/orm_stmt_wrong_return_checking_test.v',
'vlib/v/tests/orm_table_name_test.v',
'vlib/v/tests/orm_array_field_test.v',
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
'vlib/v/tests/orm_create_several_tables_test.v',
'vlib/vweb/tests/vweb_test.v',
Expand Down Expand Up @@ -271,6 +272,7 @@ const skip_on_ubuntu_musl = [
'vlib/v/tests/orm_joined_tables_select_test.v',
'vlib/v/tests/orm_stmt_wrong_return_checking_test.v',
'vlib/v/tests/orm_table_name_test.v',
'vlib/v/tests/orm_array_field_test.v',
'vlib/v/tests/orm_handle_error_for_select_from_not_created_table_test.v',
'vlib/v/tests/orm_create_several_tables_test.v',
'vlib/v/tests/sql_statement_inside_fn_call_test.v',
Expand Down
10 changes: 9 additions & 1 deletion vlib/v/checker/fn.v
Original file line number Diff line number Diff line change
Expand Up @@ -1719,7 +1719,15 @@ fn (mut c Checker) fn_call(mut node ast.CallExpr, mut continue_check &bool) ast.
} else {
func.params[i]
}
c.expected_type = param.typ
if param.typ.has_flag(.generic) {
if unwrap_typ := c.table.convert_generic_type(param.typ, func.generic_names,
concrete_types)
{
c.expected_type = unwrap_typ
}
} else {
c.expected_type = param.typ
}
already_checked := node.language != .js && call_arg.expr is ast.CallExpr
typ := c.check_expr_option_or_result_call(call_arg.expr, if already_checked
&& mut call_arg.expr is ast.CallExpr {
Expand Down
4 changes: 3 additions & 1 deletion vlib/v/gen/c/orm.v
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,9 @@ fn (mut g Gen) write_orm_insert_with_last_ids(node ast.SqlStmtLine, connection_v
if field.typ.has_flag(.option) {
opt_fields << arrs.len
}
arrs << unsafe { node.sub_structs[int(field.typ)] }
if node.sub_structs.len > 0 {
arrs << unsafe { node.sub_structs[int(field.typ)] }
}
field_names << field.name
}
}
Expand Down
29 changes: 29 additions & 0 deletions vlib/v/tests/generics/generics_with_empty_array_arg_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
fn count_str(array []string) int {
return array.len
}

fn count_int(array []int) int {
return array.len
}

fn count[T](array []T) int {
return array.len
}

fn test_generics_with_empty_array_arg() {
assert count_str(['one', 'two']) == 2
assert count_str([]string{}) == 0
assert count_str([]) == 0

assert count_int([1, 2]) == 2
assert count_int([]int{}) == 0
assert count_int([]) == 0

assert count[f64]([1.0, 2.0]) == 2
assert count[f64]([]f64{}) == 0
assert count[f64]([]) == 0

assert count[int]([1, 2]) == 2
assert count[int]([]int{}) == 0
assert count[int]([]) == 0
}
35 changes: 35 additions & 0 deletions vlib/v/tests/orm_array_field_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import time
import db.sqlite

@[table: 'task_metadata']
struct TaskMetadata {
id string @[primary]
task_id string
key string
value string
created_at time.Time @[default: 'CURRENT_TIME']
updated_at time.Time @[default: 'CURRENT_TIME']
}

@[table: 'tasks']
struct Task {
id string @[primary]
name string
metadata []TaskMetadata @[fkey: 'task_id']
}

struct MyService {
mut:
db sqlite.DB
}

pub fn (s MyService) create(record Task) int {
result := sql s.db {
insert record into Task
} or { return -1 }
return result
}

fn test_main() {
assert true
}

0 comments on commit a9e551d

Please sign in to comment.