mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
Merge 7c4905d768
into 6813a12339
This commit is contained in:
commit
2fd5465be6
@ -31,7 +31,7 @@ fn test_str_methods() {
|
||||
assert u64(-1).str() == '18446744073709551615'
|
||||
assert voidptr(-1).str() == '0xffffffffffffffff'
|
||||
assert voidptr(1).str() == '0x1'
|
||||
assert (&u8(-1)).str() == 'ffffffffffffffff'
|
||||
assert (&u8(-1)).str() == '255'
|
||||
assert (&u8(1)).str() == '1'
|
||||
assert byteptr(-1).str() == '0xffffffffffffffff'
|
||||
assert byteptr(1).str() == '0x1'
|
||||
|
@ -1382,10 +1382,11 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
}
|
||||
// TODO2
|
||||
// g.generate_tmp_autofree_arg_vars(node, name)
|
||||
if !node.receiver_type.is_ptr() && left_type.is_ptr() && node.name == 'str' {
|
||||
has_str_method := node.name == 'str' && left_sym.has_method('str')
|
||||
if !has_str_method && !node.receiver_type.is_ptr() && left_type.is_ptr() && node.name == 'str' {
|
||||
g.write('ptr_str(')
|
||||
} else if node.receiver_type.is_ptr() && left_type.is_ptr() && node.name == 'str'
|
||||
&& !left_sym.has_method('str') {
|
||||
} else if !has_str_method && node.receiver_type.is_ptr() && left_type.is_ptr()
|
||||
&& node.name == 'str' {
|
||||
g.gen_expr_to_string(node.left, left_type)
|
||||
return
|
||||
} else {
|
||||
@ -1455,6 +1456,10 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
|
||||
g.expr(node.left)
|
||||
}
|
||||
} else {
|
||||
if node.left is ast.Ident && has_str_method && left_type.is_ptr()
|
||||
&& !node.receiver_type.is_ptr() {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr(node.left)
|
||||
}
|
||||
for i, embed in node.from_embed_types {
|
||||
|
21
vlib/v/tests/str_method_call_from_mut_test.v
Normal file
21
vlib/v/tests/str_method_call_from_mut_test.v
Normal file
@ -0,0 +1,21 @@
|
||||
struct St {
|
||||
mut:
|
||||
a []u8
|
||||
}
|
||||
|
||||
pub fn (s St) str() string {
|
||||
return s.a.bytestr()
|
||||
}
|
||||
|
||||
fn confuser(mut s St) {
|
||||
assert s.str() == 'a'
|
||||
}
|
||||
|
||||
fn test_str_method_with_mut() {
|
||||
mut s := St{
|
||||
a: []u8{}
|
||||
}
|
||||
s.a << `a`
|
||||
confuser(mut s)
|
||||
assert s.str() == 'a'
|
||||
}
|
Loading…
Reference in New Issue
Block a user