mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
cgen: fix print fn + cycle const error message (#17355)
This commit is contained in:
parent
b1ed1d3b32
commit
6682911bc3
@ -3118,7 +3118,7 @@ fn (mut c Checker) ident(mut node ast.Ident) ast.Type {
|
||||
return c.expected_type
|
||||
}
|
||||
}
|
||||
c.error('cycle in constant `${c.const_decl}`', node.pos)
|
||||
c.error('cycle in constant `${c.const_var.name}`', node.pos)
|
||||
return ast.void_type
|
||||
}
|
||||
c.const_deps << name
|
||||
|
3
vlib/v/checker/tests/const_cycle_decl_err.out
Normal file
3
vlib/v/checker/tests/const_cycle_decl_err.out
Normal file
@ -0,0 +1,3 @@
|
||||
vlib/v/checker/tests/const_cycle_decl_err.vv:1:11: error: cycle in constant `a`
|
||||
1 | const a = a + 0
|
||||
| ^
|
1
vlib/v/checker/tests/const_cycle_decl_err.vv
Normal file
1
vlib/v/checker/tests/const_cycle_decl_err.vv
Normal file
@ -0,0 +1 @@
|
||||
const a = a + 0
|
@ -989,7 +989,8 @@ fn struct_auto_str_func(sym &ast.TypeSymbol, _field_type ast.Type, fn_name strin
|
||||
}
|
||||
return 'indent_${fn_name}(${obj}, indent_count + 1)', true
|
||||
} else if sym.kind == .function {
|
||||
return '${fn_name}()', true
|
||||
obj := '${deref}it.${c_name(field_name)}${sufix}'
|
||||
return '${fn_name}(${obj})', true
|
||||
} else if sym.kind == .chan {
|
||||
return '${fn_name}(${deref}it.${c_name(field_name)}${sufix})', true
|
||||
} else {
|
||||
|
@ -153,6 +153,8 @@ fn (mut g Gen) gen_expr_to_string(expr ast.Expr, etype ast.Type) {
|
||||
g.write('*')
|
||||
}
|
||||
g.expr_with_cast(expr, typ, typ)
|
||||
} else {
|
||||
g.expr_with_cast(expr, typ, typ)
|
||||
}
|
||||
g.write(')')
|
||||
}
|
||||
|
16
vlib/v/tests/print_anon_fn_test.v
Normal file
16
vlib/v/tests/print_anon_fn_test.v
Normal file
@ -0,0 +1,16 @@
|
||||
struct Foo {
|
||||
mut:
|
||||
f ?fn (int)
|
||||
g fn (int)
|
||||
}
|
||||
|
||||
fn test_main() {
|
||||
mut foo := ?Foo{}
|
||||
assert foo == none
|
||||
|
||||
foo = Foo{}
|
||||
assert foo != none
|
||||
|
||||
println(foo?.f)
|
||||
println('${foo?.f}')
|
||||
}
|
Loading…
Reference in New Issue
Block a user