From 6a74b453ef012294786130cdd88f1cfce2686651 Mon Sep 17 00:00:00 2001 From: Markku Rossi Date: Thu, 25 Jul 2024 15:59:04 +0200 Subject: [PATCH] Empty slices can be instantiated in variable declaration time. --- compiler/ast/ssagen.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/compiler/ast/ssagen.go b/compiler/ast/ssagen.go index c1eaffc..69fc25a 100644 --- a/compiler/ast/ssagen.go +++ b/compiler/ast/ssagen.go @@ -149,8 +149,13 @@ func (ast *VariableDef) SSA(block *ssa.Block, ctx *Codegen, return nil, nil, ctx.Errorf(ast, "undefined variable") } if !typeInfo.Concrete() { - return nil, nil, ctx.Errorf(ast.Type, - "unspecified size for type %v", ast.Type) + if typeInfo.Type != types.TSlice { + return nil, nil, ctx.Errorf(ast.Type, + "unspecified size for type %v", ast.Type) + } + // Empty slices can be instantiated in variable + // declaration time. + typeInfo.SetConcrete(true) } initVal, err := initValue(typeInfo) if err != nil {