1
0
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:
Felipe Pena 2023-02-22 08:38:08 -03:00 committed by GitHub
parent b1ed1d3b32
commit 6682911bc3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 25 additions and 2 deletions

View File

@ -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

View 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
| ^

View File

@ -0,0 +1 @@
const a = a + 0

View File

@ -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 {

View File

@ -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(')')
}

View 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}')
}