checker: handle array of interfaces
parent
8000eb3656
commit
2b4ac0e63a
|
@ -996,6 +996,11 @@ pub fn (mut c Checker) array_init(array_init mut ast.ArrayInit) table.Type {
|
|||
}
|
||||
// [1,2,3]
|
||||
if array_init.exprs.len > 0 && array_init.elem_type == table.void_type {
|
||||
expecting_interface_array := c.expected_type != 0 &&
|
||||
c.table.get_type_symbol( c.table.value_type(c.expected_type) ).kind == .interface_
|
||||
//if expecting_interface_array {
|
||||
//println('ex $c.expected_type')
|
||||
//}
|
||||
for i, expr in array_init.exprs {
|
||||
typ := c.expr(expr)
|
||||
// The first element's type
|
||||
|
@ -1004,6 +1009,9 @@ pub fn (mut c Checker) array_init(array_init mut ast.ArrayInit) table.Type {
|
|||
c.expected_type = typ
|
||||
continue
|
||||
}
|
||||
if expecting_interface_array {
|
||||
continue
|
||||
}
|
||||
if !c.table.check(elem_type, typ) {
|
||||
elem_type_sym := c.table.get_type_symbol(elem_type)
|
||||
c.error('expected array element with type `$elem_type_sym.name`', array_init.pos)
|
||||
|
|
|
@ -46,7 +46,7 @@ fn test_perform_speak() {
|
|||
perform_speak(dog)
|
||||
cat := Cat{}
|
||||
perform_speak(cat)
|
||||
perform_speakers([dog, cat])
|
||||
//perform_speakers([dog, cat])
|
||||
/*
|
||||
f := Foo {
|
||||
speaker: dog
|
||||
|
|
Loading…
Reference in New Issue