mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: minor fixes
This commit is contained in:
parent
211d35d647
commit
3f6ccd3120
@ -142,7 +142,7 @@ pub fn new_v(args []string) &compiler.V {
|
|||||||
build_mode: build_mode
|
build_mode: build_mode
|
||||||
cflags: cflags
|
cflags: cflags
|
||||||
ccompiler: ccompiler
|
ccompiler: ccompiler
|
||||||
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v.v' || rdir_name == 'vfmt.v' || rdir_name == 'cmd/v' || dir.contains('vlib'))
|
building_v: !is_repl && (rdir_name == 'compiler' || rdir_name == 'v' || rdir_name == 'vfmt.v' || rdir_name == 'cmd/v' || dir.contains('vlib'))
|
||||||
// is_fmt: comptime_define == 'vfmt'
|
// is_fmt: comptime_define == 'vfmt'
|
||||||
|
|
||||||
user_mod_path: user_mod_path
|
user_mod_path: user_mod_path
|
||||||
|
@ -78,7 +78,7 @@ fn (c &Checker) complete_types() {
|
|||||||
info.key_type = c.resolve(info.key_type)
|
info.key_type = c.resolve(info.key_type)
|
||||||
updated = true
|
updated = true
|
||||||
}
|
}
|
||||||
if table.type_is_unresolved(info.value_type) {
|
if table.type_is_unresolved(info.value_type) {
|
||||||
info.value_type = c.resolve(info.value_type)
|
info.value_type = c.resolve(info.value_type)
|
||||||
updated = true
|
updated = true
|
||||||
}
|
}
|
||||||
@ -111,13 +111,13 @@ fn (c &Checker) complete_types() {
|
|||||||
|
|
||||||
// return the resolved Type from unresovled Type
|
// return the resolved Type from unresovled Type
|
||||||
pub fn (c &Checker) resolve(unresolved table.Type) table.Type {
|
pub fn (c &Checker) resolve(unresolved table.Type) table.Type {
|
||||||
return c.resolved[-table.type_idx(unresolved)-1]
|
return c.resolved[-table.type_idx(unresolved) - 1]
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn (c &Checker) check_struct_init(struct_init ast.StructInit) table.Type {
|
pub fn (c &Checker) check_struct_init(struct_init ast.StructInit) table.Type {
|
||||||
// typ := c.table.find_type(struct_init.typ.typ.name) or {
|
// typ := c.table.find_type(struct_init.typ.typ.name) or {
|
||||||
// c.error('unknown struct: $struct_init.typ.typ.name', struct_init.pos)
|
// c.error('unknown struct: $struct_init.typ.typ.name', struct_init.pos)
|
||||||
// panic('')
|
// panic('')
|
||||||
// }
|
// }
|
||||||
typ := c.table.get_type_symbol(struct_init.typ)
|
typ := c.table.get_type_symbol(struct_init.typ)
|
||||||
match typ.kind {
|
match typ.kind {
|
||||||
@ -171,29 +171,24 @@ pub fn (c &Checker) call_expr(call_expr ast.CallExpr) table.Type {
|
|||||||
fn_name := call_expr.name
|
fn_name := call_expr.name
|
||||||
if f := c.table.find_fn(fn_name) {
|
if f := c.table.find_fn(fn_name) {
|
||||||
// return_ti := f.return_ti
|
// return_ti := f.return_ti
|
||||||
if /*TODO:*/!f.is_c {
|
if f.is_c {
|
||||||
if call_expr.args.len < f.args.len {
|
return f.return_type
|
||||||
c.error('too few arguments in call to `$fn_name`', call_expr.pos)
|
}
|
||||||
}
|
if call_expr.args.len < f.args.len {
|
||||||
else if !f.is_variadic && call_expr.args.len > f.args.len {
|
c.error('too few arguments in call to `$fn_name`', call_expr.pos)
|
||||||
c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos)
|
}
|
||||||
}
|
else if !f.is_variadic && call_expr.args.len > f.args.len {
|
||||||
|
c.error('too many arguments in call to `$fn_name` ($call_expr.args.len instead of $f.args.len)', call_expr.pos)
|
||||||
}
|
}
|
||||||
if /*TODO:*/!f.is_c {
|
|
||||||
for i, arg_expr in call_expr.args {
|
for i, arg_expr in call_expr.args {
|
||||||
arg := if f.is_variadic && i >= f.args.len-1 {
|
arg := if f.is_variadic && i >= f.args.len - 1 { f.args[f.args.len - 1] } else { f.args[i] }
|
||||||
f.args[f.args.len-1]
|
|
||||||
} else {
|
|
||||||
f.args[i]
|
|
||||||
}
|
|
||||||
typ := c.expr(arg_expr)
|
typ := c.expr(arg_expr)
|
||||||
typ_sym := c.table.get_type_symbol(typ)
|
typ_sym := c.table.get_type_symbol(typ)
|
||||||
arg_typ_sym := c.table.get_type_symbol(arg.typ)
|
arg_typ_sym := c.table.get_type_symbol(arg.typ)
|
||||||
if /*TODO:*/!f.is_c && !c.table.check(typ, arg.typ) {
|
if !c.table.check(typ, arg.typ) {
|
||||||
c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos)
|
c.error('!cannot use type `$typ_sym.name` as type `$arg_typ_sym.name` in argument ${i+1} to `$fn_name`', call_expr.pos)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return f.return_type
|
return f.return_type
|
||||||
}
|
}
|
||||||
c.error('unknown fn: $fn_name', call_expr.pos)
|
c.error('unknown fn: $fn_name', call_expr.pos)
|
||||||
|
Loading…
Reference in New Issue
Block a user