gen: fix type_name for sumtype/interface pointers (#8769)

pull/8662/head
spaceface 2021-02-15 16:35:31 +01:00 committed by GitHub
parent 4213851e22
commit fe007f9b16
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -534,13 +534,15 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
if left_sym.kind == .sum_type && node.name == 'type_name' {
g.write('tos3( /* $left_sym.name */ v_typeof_sumtype_${typ_sym.cname}( (')
g.expr(node.left)
g.write(').typ ))')
dot := if node.left_type.is_ptr() { '->' } else { '.' }
g.write(')${dot}typ ))')
return
}
if left_sym.kind == .interface_ && node.name == 'type_name' {
g.write('tos3( /* $left_sym.name */ v_typeof_interface_${typ_sym.cname}( (')
g.expr(node.left)
g.write(')._interface_idx ))')
dot := if node.left_type.is_ptr() { '->' } else { '.' }
g.write(')${dot}_interface_idx ))')
return
}
if node.name == 'str' {