v.gen.c: fix error of `println(alias of struct)` (#11062)

pull/11064/head
yuyi 2021-08-06 01:20:10 +08:00 committed by GitHub
parent 11784279ba
commit c30cda3daf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 6 deletions

View File

@ -962,12 +962,6 @@ fn (mut g Gen) fn_call(node ast.CallExpr) {
if typ == 0 { if typ == 0 {
g.checker_bug('print arg.typ is 0', node.pos) g.checker_bug('print arg.typ is 0', node.pos)
} }
mut sym := g.table.get_type_symbol(typ)
if mut sym.info is ast.Alias {
typ = sym.info.parent_type
sym = g.table.get_type_symbol(typ)
}
// check if alias parent also not a string
if typ != ast.string_type { if typ != ast.string_type {
expr := node.args[0].expr expr := node.args[0].expr
if g.is_autofree && !typ.has_flag(.optional) { if g.is_autofree && !typ.has_flag(.optional) {

View File

@ -0,0 +1,27 @@
interface Foo {
add(x int)
}
struct Base {
mut:
i int
}
fn (mut b Base) add(x int) {
b.i += x
}
type Alias = Base
fn (mut a Alias) add(x int) {
a.i += x * x
}
fn test_string_alias_of_struct() {
mut a := Alias{
i: 2
}
a.add(3)
println(a)
assert '$a'.contains('Alias')
}