Skip to content

Commit f4fbba2

Browse files
committed
cgen: keep interface typeof independent of builtin string
1 parent 0ffc857 commit f4fbba2

4 files changed

Lines changed: 20 additions & 8 deletions

File tree

vlib/v/gen/c/cgen.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,11 +1229,11 @@ pub fn (mut g Gen) write_typeof_functions() {
12291229
continue
12301230
}
12311231
already_generated_ifaces[sym.cname] = true
1232-
g.definitions.writeln('${g.static_non_parallel}string v_typeof_interface_${sym.cname}(u32 sidx);')
1232+
g.definitions.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx);')
12331233
if g.pref.parallel_cc {
1234-
g.extern_out.writeln('extern string v_typeof_interface_${sym.cname}(u32 sidx);')
1234+
g.extern_out.writeln('extern char * v_typeof_interface_${sym.cname}(u32 sidx);')
12351235
}
1236-
g.writeln('${g.static_non_parallel}string v_typeof_interface_${sym.cname}(u32 sidx) {')
1236+
g.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx) {')
12371237
for t in inter_info.types {
12381238
sub_sym := g.table.sym(ast.mktyp(t))
12391239
if sub_sym.info is ast.Struct && sub_sym.info.is_unresolved_generic() {
@@ -1243,9 +1243,9 @@ pub fn (mut g Gen) write_typeof_functions() {
12431243
&& sub_sym.idx !in g.table.used_features.used_syms {
12441244
continue
12451245
}
1246-
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return _S("${util.strip_main_name(sub_sym.name)}");')
1246+
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
12471247
}
1248-
g.writeln2('\treturn _S("unknown ${util.strip_main_name(sym.name)}");', '}')
1248+
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
12491249
// Avoid duplicate symbol '_v_typeof_interface_idx_IError' when using -usecache
12501250
if g.pref.build_mode != .build_module {
12511251
g.definitions.writeln('u32 v_typeof_interface_idx_${sym.cname}(u32 sidx);')
@@ -8895,7 +8895,7 @@ return ${cast_shared_struct_str};
88958895
variant_sym := g.table.sym(variant)
88968896
conversion_functions.writeln('\tif (x._typ == _${interface_name}_${variant_sym.cname}_index) return I_${variant_sym.cname}_to_Interface_${vsym.cname}(x._${variant_sym.cname});')
88978897
}
8898-
pmessage := 'builtin__string__plus(builtin__string__plus(_S("`as_cast`: cannot convert "), v_typeof_interface_${interface_name}(x._typ)), _S(" to ${util.strip_main_name(vsym.name)}"))'
8898+
pmessage := 'builtin__string__plus(builtin__string__plus(_S("`as_cast`: cannot convert "), builtin__tos3(v_typeof_interface_${interface_name}(x._typ))), _S(" to ${util.strip_main_name(vsym.name)}"))'
88998899
if g.pref.is_debug {
89008900
// TODO: actually return a valid position here
89018901
conversion_functions.write_string2('\tbuiltin__panic_debug(1, builtin__tos3("builtin.v"), builtin__tos3("builtin"), builtin__tos3("__as_cast"), ',

vlib/v/gen/c/fn.v

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,8 +1796,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
17961796
')', node)
17971797
return
17981798
} else if left_sym.kind == .interface {
1799-
g.conversion_function_call('v_typeof_interface_${typ_sym.cname}',
1800-
'', node)
1799+
g.conversion_function_call('builtin__tos3(v_typeof_interface_${typ_sym.cname}',
1800+
')', node)
18011801
return
18021802
}
18031803
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
static char * v_typeof_interface_main__Thing(u32 sidx) {
2+
if (sidx == _main__Thing_main__Item_index) return "Item";
3+
return "unknown Thing";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// vtest vflags: -no-builtin
2+
interface Thing {}
3+
4+
struct Item {}
5+
6+
fn main() {
7+
h := Thing(Item{})
8+
_ = h
9+
}

0 commit comments

Comments
 (0)