mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v2: handle variadic in selector_expr
This commit is contained in:
parent
71b5b0d955
commit
48f912c2e9
@ -239,6 +239,12 @@ pub fn (c mut Checker) selector_expr(selector_expr ast.SelectorExpr) table.Type
|
|||||||
if field := typ_sym.find_field(field_name) {
|
if field := typ_sym.find_field(field_name) {
|
||||||
return field.typ
|
return field.typ
|
||||||
}
|
}
|
||||||
|
// variadic
|
||||||
|
if table.type_is_variadic(typ) {
|
||||||
|
if field_name == 'len' {
|
||||||
|
return table.int_type
|
||||||
|
}
|
||||||
|
}
|
||||||
// check parent
|
// check parent
|
||||||
if typ_sym.parent_idx != 0 {
|
if typ_sym.parent_idx != 0 {
|
||||||
parent := &c.table.types[typ_sym.parent_idx]
|
parent := &c.table.types[typ_sym.parent_idx]
|
||||||
|
@ -205,7 +205,10 @@ fn (p mut Parser) fn_args() ([]ast.Arg,bool) {
|
|||||||
p.check(.ellipsis)
|
p.check(.ellipsis)
|
||||||
is_variadic = true
|
is_variadic = true
|
||||||
}
|
}
|
||||||
arg_type := p.parse_type()
|
mut arg_type := p.parse_type()
|
||||||
|
if is_variadic {
|
||||||
|
arg_type = table.type_to_variadic(arg_type)
|
||||||
|
}
|
||||||
if p.tok.kind == .comma {
|
if p.tok.kind == .comma {
|
||||||
if is_variadic {
|
if is_variadic {
|
||||||
p.error('cannot use ...(variadic) with non-final parameter no $arg_no')
|
p.error('cannot use ...(variadic) with non-final parameter no $arg_no')
|
||||||
@ -234,7 +237,10 @@ fn (p mut Parser) fn_args() ([]ast.Arg,bool) {
|
|||||||
p.check(.ellipsis)
|
p.check(.ellipsis)
|
||||||
is_variadic = true
|
is_variadic = true
|
||||||
}
|
}
|
||||||
typ := p.parse_type()
|
mut typ := p.parse_type()
|
||||||
|
if is_variadic {
|
||||||
|
typ = table.type_to_variadic(typ)
|
||||||
|
}
|
||||||
for arg_name in arg_names {
|
for arg_name in arg_names {
|
||||||
args << ast.Arg{
|
args << ast.Arg{
|
||||||
name: arg_name
|
name: arg_name
|
||||||
|
@ -5,6 +5,7 @@ pub type Type int
|
|||||||
pub enum TypeExtra {
|
pub enum TypeExtra {
|
||||||
unset
|
unset
|
||||||
optional
|
optional
|
||||||
|
variadic
|
||||||
}
|
}
|
||||||
|
|
||||||
// return underlying TypeSymbol idx
|
// return underlying TypeSymbol idx
|
||||||
@ -76,6 +77,16 @@ pub fn type_to_optional(t Type) Type {
|
|||||||
return type_set_extra(t, .optional)
|
return type_set_extra(t, .optional)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[inline]
|
||||||
|
pub fn type_is_variadic(t Type) bool {
|
||||||
|
return type_extra(t) == .variadic
|
||||||
|
}
|
||||||
|
|
||||||
|
[inline]
|
||||||
|
pub fn type_to_variadic(t Type) Type {
|
||||||
|
return type_set_extra(t, .variadic)
|
||||||
|
}
|
||||||
|
|
||||||
// new type with idx of TypeSymbol, not pointer (nr_muls=0)
|
// new type with idx of TypeSymbol, not pointer (nr_muls=0)
|
||||||
[inline]
|
[inline]
|
||||||
pub fn new_type(idx int) Type {
|
pub fn new_type(idx int) Type {
|
||||||
|
Loading…
Reference in New Issue
Block a user