ast: fix error for typeof aggregate (#13735)
parent
d6eb6d5bae
commit
ea3c0166c0
|
@ -1122,9 +1122,10 @@ pub fn (t &Table) type_to_str_using_aliases(typ Type, import_aliases map[string]
|
|||
res = 'thread ' + t.type_to_str_using_aliases(rtype, import_aliases)
|
||||
}
|
||||
}
|
||||
.alias, .any, .aggregate, .placeholder, .enum_ {
|
||||
.alias, .any, .placeholder, .enum_ {
|
||||
res = t.shorten_user_defined_typenames(res, import_aliases)
|
||||
}
|
||||
.aggregate {}
|
||||
}
|
||||
mut nr_muls := typ.nr_muls()
|
||||
if typ.has_flag(.shared_f) {
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
struct Foo {
|
||||
}
|
||||
|
||||
struct Bar {
|
||||
text string
|
||||
}
|
||||
|
||||
struct Baz {
|
||||
text string
|
||||
}
|
||||
|
||||
struct Bazaar {
|
||||
text string
|
||||
}
|
||||
|
||||
type FBB = Bar | Baz | Bazaar | Foo
|
||||
|
||||
fn test_typeof_aggregate() {
|
||||
mut arr := []FBB{}
|
||||
arr << Foo{}
|
||||
arr << Bar{
|
||||
text: 'bar'
|
||||
}
|
||||
arr << Baz{
|
||||
text: 'baz'
|
||||
}
|
||||
|
||||
mut rets := []string{}
|
||||
for a in arr {
|
||||
match a {
|
||||
Foo {
|
||||
println('The type of `a` is `${typeof(a).name}`')
|
||||
rets << 'The type of `a` is `${typeof(a).name}`'
|
||||
}
|
||||
Bar, Baz, Bazaar {
|
||||
println('The type of `a` is `${typeof(a).name}` and its text says $a.text')
|
||||
rets << 'The type of `a` is `${typeof(a).name}` and its text says $a.text'
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
assert rets.len == 3
|
||||
assert rets[0] == 'The type of `a` is `Foo`'
|
||||
assert rets[1] == 'The type of `a` is `(Bar | Baz | Bazaar)` and its text says bar'
|
||||
assert rets[2] == 'The type of `a` is `(Bar | Baz | Bazaar)` and its text says baz'
|
||||
}
|
Loading…
Reference in New Issue