v.gen.c: fix error of `println(alias of struct)` (#11062)
parent
11784279ba
commit
c30cda3daf
|
@ -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) {
|
||||||
|
|
|
@ -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')
|
||||||
|
}
|
Loading…
Reference in New Issue