@@ -4890,11 +4890,15 @@ fn (mut g Gen) const_decl_simple_define(mod string, name string, val string) {
4890
4890
}
4891
4891
}
4892
4892
4893
+ fn (mut g Gen) c_const_name (name string ) string {
4894
+ return if g.pref.translated && ! g.is_builtin_mod { name } else { '_const_${name} ' }
4895
+ }
4896
+
4893
4897
fn (mut g Gen) const_decl_init_later (mod string , name string , expr ast.Expr, typ ast.Type, unwrap_option bool ) {
4894
4898
// Initialize more complex consts in `void _vinit/2{}`
4895
4899
// (C doesn't allow init expressions that can't be resolved at compile time).
4896
4900
mut styp := g.typ (typ)
4897
- cname := if g.pref.translated && ! g.is_builtin_mod { name } else { '_const_ ${name} ' }
4901
+ cname := g. c_const_name ( name)
4898
4902
mut init := strings.new_builder (100 )
4899
4903
if cname == '_const_os__args' {
4900
4904
if g.pref.os == .windows {
@@ -4911,9 +4915,16 @@ fn (mut g Gen) const_decl_init_later(mod string, name string, expr ast.Expr, typ
4911
4915
init.writeln (g.expr_string_surround ('\t ${cname} = ' , expr, ';' ))
4912
4916
}
4913
4917
}
4918
+ mut def := '${styp} ${cname} '
4919
+ expr_sym := g.table.sym (typ)
4920
+ if expr_sym.kind == .function {
4921
+ // allow for: `const xyz = abc`, where `abc` is `fn abc() {}`
4922
+ func := (expr_sym.info as ast.FnType ).func
4923
+ def = g.fn_var_signature (func.return_type, func.params.map (it .typ), cname)
4924
+ }
4914
4925
g.global_const_defs[util.no_dots (name)] = GlobalConstDef{
4915
4926
mod: mod
4916
- def: '${styp} ${cname } ; // inited later'
4927
+ def: '${def } ; // inited later'
4917
4928
init: init.str ().trim_right ('\n ' )
4918
4929
dep_names: g.table.dependent_names_in_expr (expr)
4919
4930
}
0 commit comments