mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: do not allow string(int)
This commit is contained in:
parent
c5d295c378
commit
a0ca68ce3f
@ -18,7 +18,7 @@ const (
|
||||
|
||||
fn C.symlink(charptr, charptr) int
|
||||
|
||||
fn init_os_args(argc int, argv &byteptr) []string {
|
||||
fn init_os_args(argc int, argv &&byte) []string {
|
||||
mut args := []string{}
|
||||
//mut args := []string(make(0, argc, sizeof(string)))
|
||||
//mut args := []string{len:argc}
|
||||
|
@ -678,6 +678,7 @@ pub:
|
||||
expr Expr // `buf`
|
||||
arg Expr // `n` in `string(buf, n)`
|
||||
typ table.Type // `string`
|
||||
pos token.Position
|
||||
mut:
|
||||
typname string
|
||||
expr_type table.Type // `byteptr`
|
||||
|
@ -1516,6 +1516,10 @@ pub fn (mut c Checker) expr(node ast.Expr) table.Type {
|
||||
c.expr(it.arg)
|
||||
}
|
||||
it.typname = c.table.get_type_symbol(it.typ).name
|
||||
if it.typ == table.string_type && !it.has_arg && it.expr_type.is_number() && !it.expr_type.is_ptr() {
|
||||
// s := c.table.get_type_symbol(it.expr_type)
|
||||
c.error('use `number.str()` instead of `string(number)`', it.pos)
|
||||
}
|
||||
return it.typ
|
||||
}
|
||||
ast.CallExpr {
|
||||
|
@ -674,6 +674,7 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|
||||
expr: expr
|
||||
arg: arg
|
||||
has_arg: has_arg
|
||||
pos: p.tok.position()
|
||||
}
|
||||
p.expr_mod = ''
|
||||
return node
|
||||
|
@ -195,7 +195,8 @@ pub const (
|
||||
signed_integer_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx]
|
||||
unsigned_integer_type_idxs = [byte_type_idx, u16_type_idx, u32_type_idx, u64_type_idx]
|
||||
float_type_idxs = [f32_type_idx, f64_type_idx]
|
||||
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx, i64_type_idx, byte_type_idx,
|
||||
number_type_idxs = [i8_type_idx, i16_type_idx, int_type_idx,
|
||||
i64_type_idx, byte_type_idx,
|
||||
u16_type_idx,
|
||||
u32_type_idx,
|
||||
u64_type_idx,
|
||||
|
Loading…
Reference in New Issue
Block a user