File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -141,7 +141,12 @@ fn ensure_string_eq_impl(source string) string {
141141
142142fn replace_generated_c_fn (source string , signature string , replacement string ) string {
143143 needle := signature + ' {'
144- start := source.index (needle) or { return source }
144+ // Search for the needle preceded by a newline to ensure we match an actual
145+ // function definition at the start of a line, not an occurrence inside a
146+ // string literal (e.g. when the compiler compiles itself).
147+ full_needle := '\n ' + needle
148+ nl_pos := source.index (full_needle) or { return source }
149+ start := nl_pos + 1 // skip the newline itself
145150 body_start := start + needle.len - 1
146151 if body_start < 0 || body_start > = source.len || source[body_start] != `{` {
147152 return source
Original file line number Diff line number Diff line change @@ -389,6 +389,11 @@ fn (mut g Gen) gen_assign_stmt(node ast.AssignStmt) {
389389 scope_type := g.types_type_to_c (raw_type)
390390 if scope_type != '' && scope_type != 'int' {
391391 typ = scope_type
392+ // Ensure result/option wrapper types are registered so their
393+ // typedef and struct definitions get emitted in the C output.
394+ if scope_type.starts_with ('_result_' ) || scope_type.starts_with ('_option_' ) {
395+ g.register_alias_type (scope_type)
396+ }
392397 } else if scope_type == 'int' && typ == 'bool' {
393398 // Fix: literal like `1` mistyped as bool in env
394399 typ = 'int'
You can’t perform that action at this time.
0 commit comments