mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parent
005676fe60
commit
29857cb9d6
@ -390,6 +390,10 @@ pub fn (mut c Checker) string_inter_lit(mut node ast.StringInterLiteral) table.T
|
||||
}
|
||||
node.need_fmts[i] = fmt != c.get_default_fmt(ftyp, typ)
|
||||
}
|
||||
// check recursive str
|
||||
if c.cur_fn.is_method && c.cur_fn.name == 'str' && c.cur_fn.receiver.name == expr.str() {
|
||||
c.error('cannot call `str()` method recursively', expr.position())
|
||||
}
|
||||
}
|
||||
return table.string_type
|
||||
}
|
||||
|
7
vlib/v/checker/tests/interpolation_recursive_str_err.out
Normal file
7
vlib/v/checker/tests/interpolation_recursive_str_err.out
Normal file
@ -0,0 +1,7 @@
|
||||
vlib/v/checker/tests/interpolation_recursive_str_err.vv:8:8: error: cannot call `str()` method recursively
|
||||
6 |
|
||||
7 | fn (t Test) str() string {
|
||||
8 | _ = '$t'
|
||||
| ^
|
||||
9 | return 'test'
|
||||
10 | }
|
15
vlib/v/checker/tests/interpolation_recursive_str_err.vv
Normal file
15
vlib/v/checker/tests/interpolation_recursive_str_err.vv
Normal file
@ -0,0 +1,15 @@
|
||||
module main
|
||||
|
||||
struct Test {
|
||||
a int
|
||||
}
|
||||
|
||||
fn (t Test) str() string {
|
||||
_ = '$t'
|
||||
return 'test'
|
||||
}
|
||||
|
||||
fn main() {
|
||||
a := Test{}
|
||||
println(a)
|
||||
}
|
Loading…
Reference in New Issue
Block a user