Skip to content

Commit 36ee17d

Browse files
committed
cgen: keep interface typeof independent of builtin string
1 parent 99f141f commit 36ee17d

6 files changed

Lines changed: 29 additions & 7 deletions

File tree

vlib/v/gen/c/cgen.v

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,11 @@ pub fn (mut g Gen) write_typeof_functions() {
13881388
}
13891389
already_generated_ifaces[sym.cname] = true
13901390
impl_types := inter_info.implementor_types(true)
1391-
g.definitions.writeln('${g.static_non_parallel}string v_typeof_interface_${sym.cname}(u32 sidx);')
1391+
g.definitions.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx);')
13921392
if g.pref.parallel_cc {
1393-
g.extern_out.writeln('extern string v_typeof_interface_${sym.cname}(u32 sidx);')
1393+
g.extern_out.writeln('extern char * v_typeof_interface_${sym.cname}(u32 sidx);')
13941394
}
1395-
g.writeln('${g.static_non_parallel}string v_typeof_interface_${sym.cname}(u32 sidx) {')
1395+
g.writeln('${g.static_non_parallel}char * v_typeof_interface_${sym.cname}(u32 sidx) {')
13961396
for t in impl_types {
13971397
sub_sym := g.table.sym(ast.mktyp(t))
13981398
if sub_sym.kind == .interface {
@@ -1405,9 +1405,9 @@ pub fn (mut g Gen) write_typeof_functions() {
14051405
&& sub_sym.idx !in g.table.used_features.used_syms {
14061406
continue
14071407
}
1408-
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return _S("${util.strip_main_name(sub_sym.name)}");')
1408+
g.writeln('\tif (sidx == _${sym.cname}_${sub_sym.cname}_index) return "${util.strip_main_name(sub_sym.name)}";')
14091409
}
1410-
g.writeln2('\treturn _S("unknown ${util.strip_main_name(sym.name)}");', '}')
1410+
g.writeln2('\treturn "unknown ${util.strip_main_name(sym.name)}";', '}')
14111411
// Avoid duplicate symbol '_v_typeof_interface_idx_IError' when using -usecache
14121412
if g.pref.build_mode != .build_module {
14131413
interface_idx_static_prefix := if g.pref.is_o { 'static ' } else { '' }
@@ -11664,7 +11664,7 @@ return ${cast_shared_struct_str};
1166411664
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});')
1166511665
}
1166611666
}
11667-
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)}"))'
11667+
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)}"))'
1166811668
if g.pref.is_debug {
1166911669
// TODO: actually return a valid position here
1167011670
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 & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4194,7 +4194,8 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
41944194
')', node)
41954195
return
41964196
} else if left_sym.kind == .interface {
4197-
g.conversion_function_call('v_typeof_interface_${typ_sym.cname}', '', node)
4197+
g.conversion_function_call('builtin__charptr_vstring_literal(v_typeof_interface_${typ_sym.cname}',
4198+
')', node)
41984199
return
41994200
}
42004201
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
builtin__charptr_vstring_literal(v_typeof_interface_main__Thing(
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
interface Thing {}
2+
3+
struct Item {}
4+
5+
fn main() {
6+
t := Thing(Item{})
7+
println(t.type_name())
8+
}
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)