Skip to content

Commit 7b6cdd2

Browse files
committed
v2: minor fixes
1 parent 4ac610c commit 7b6cdd2

2 files changed

Lines changed: 11 additions & 1 deletion

File tree

‎vlib/v2/builder/builder.v‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ fn ensure_string_eq_impl(source string) string {
141141

142142
fn 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

‎vlib/v2/gen/cleanc/assign.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff 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'

0 commit comments

Comments
 (0)