diff --git a/lang/funcs/structs/composite.go b/lang/funcs/structs/composite.go index 7fccd505..1e906181 100644 --- a/lang/funcs/structs/composite.go +++ b/lang/funcs/structs/composite.go @@ -119,6 +119,20 @@ func (obj *CompositeFunc) Stream() error { select { case input, ok := <-obj.init.Input: if !ok { + obj.init.Input = nil // don't infinite loop back + + if obj.last == nil { + // FIXME: can we get an empty struct? + result := obj.Type.New() // new list or map + obj.result = result + select { + case obj.init.Output <- result: // send + // pass + case <-obj.closeChan: + return nil + } + } + return nil // can't output any more } //if err := input.Type().Cmp(obj.Info().Sig.Input); err != nil { diff --git a/lang/interpret_test/TestAstFunc2/empty-list.output b/lang/interpret_test/TestAstFunc2/empty-list.output new file mode 100644 index 00000000..08e8bc52 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/empty-list.output @@ -0,0 +1 @@ +Vertex: test[name] diff --git a/lang/interpret_test/TestAstFunc2/empty-list/main.mcl b/lang/interpret_test/TestAstFunc2/empty-list/main.mcl new file mode 100644 index 00000000..f9253ef0 --- /dev/null +++ b/lang/interpret_test/TestAstFunc2/empty-list/main.mcl @@ -0,0 +1,5 @@ +# make sure the engine works with empty values +test "name" { + slicestring => [], # empty list + mapintfloat => {}, # empty map +}