json: handle external types

pull/4764/head
wilesun 2020-05-07 10:33:19 +08:00 committed by GitHub
parent 98a1b2782b
commit 19390871e9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 5 deletions

View File

@ -1548,11 +1548,11 @@ fn (mut g Gen) infix_expr(node ast.InfixExpr) {
g.expr(node.left) g.expr(node.left)
g.write(', &($elem_type_str[]){ ') g.write(', &($elem_type_str[]){ ')
elem_sym := g.table.get_type_symbol(info.elem_type) elem_sym := g.table.get_type_symbol(info.elem_type)
if elem_sym.kind == .interface_ { if elem_sym.kind == .interface_ && node.right_type != info.elem_type{
g.interface_call(node.right_type, info.elem_type) g.interface_call(node.right_type, info.elem_type)
} }
g.expr_with_cast(node.right, node.right_type, info.elem_type) g.expr_with_cast(node.right, node.right_type, info.elem_type)
if elem_sym.kind == .interface_ { if elem_sym.kind == .interface_ && node.right_type != info.elem_type{
g.write(')') g.write(')')
} }
g.write(' })') g.write(' })')
@ -3535,7 +3535,7 @@ fn (g &Gen) interface_table() string {
cast_functions.writeln(' cast_functions.writeln('
_Interface I_${cctype}_to_Interface_${interface_name}(${cctype}* x) { _Interface I_${cctype}_to_Interface_${interface_name}(${cctype}* x) {
return (_Interface) { return (_Interface) {
._object = (void*) memdup(x, sizeof(${cctype})), ._object = (void*) (x),
._interface_idx = ${interface_index_name} ._interface_idx = ${interface_index_name}
}; };
}') }')

View File

@ -103,12 +103,12 @@ cJSON* ${enc_fn_name}($styp val) {
fn js_enc_name(typ string) string { fn js_enc_name(typ string) string {
name := 'json__encode_$typ' name := 'json__encode_$typ'
return name return name.replace('.', '__')
} }
fn js_dec_name(typ string) string { fn js_dec_name(typ string) string {
name := 'json__decode_$typ' name := 'json__decode_$typ'
return name return name.replace('.', '__')
} }
fn is_js_prim(typ string) bool { fn is_js_prim(typ string) bool {