@@ -277,22 +277,13 @@ func (c *Compiler) ArrayGetBorrowed(arr *Symbol, elem Type, idx llvm.Value) llvm
277277
278278// compileArrayExpression materializes a bracket literal according to its solved
279279// Array or Table type.
280- func (c * Compiler ) compileArrayExpression (e * ast.ArrayLiteral , _ []* ast.Identifier ) ( res []* Symbol ) {
280+ func (c * Compiler ) compileArrayExpression (e * ast.ArrayLiteral , _ []* ast.Identifier ) []* Symbol {
281281 lit , info := c .resolveArrayLiteralRewrite (e )
282282 switch typ := info .OutTypes [0 ].(type ) {
283283 case Array :
284- if typ .Rank > 1 {
285- if c .arrayLiteralHasArrayCells (lit ) {
286- if len (info .CollectRanges ) > 0 {
287- return []* Symbol {c .compileStackedArrayCollector (lit , info , typ )}
288- }
289- return []* Symbol {c .compileStackedArrayLiteral (lit , typ )}
290- }
291- return []* Symbol {c .compileRectangularArrayLiteral (lit , typ )}
292- }
293- return []* Symbol {c .compileArrayLiteralInDomain (lit , info , nil , nil )}
284+ return []* Symbol {c .compileArray (lit , info , typ )}
294285 case Table :
295- return []* Symbol {c .compileTableLiteral (lit , typ )}
286+ return []* Symbol {c .compileTable (lit , typ )}
296287 default :
297288 c .Errors = append (c .Errors , & token.CompileError {
298289 Token : lit .Tok (),
@@ -302,6 +293,19 @@ func (c *Compiler) compileArrayExpression(e *ast.ArrayLiteral, _ []*ast.Identifi
302293 }
303294}
304295
296+ func (c * Compiler ) compileArray (lit * ast.ArrayLiteral , info * ExprInfo , arrayType Array ) * Symbol {
297+ if arrayType .Rank == 1 {
298+ return c .compileArrayLiteralInDomain (lit , info , nil , nil )
299+ }
300+ if ! c .arrayLiteralHasArrayCells (lit ) {
301+ return c .compileRectangularArrayLiteral (lit , arrayType )
302+ }
303+ if len (info .CollectRanges ) == 0 {
304+ return c .compileStackedArrayLiteral (lit , arrayType )
305+ }
306+ return c .compileStackedArrayCollector (lit , info , arrayType )
307+ }
308+
305309func (c * Compiler ) arrayLiteralHasArrayCells (lit * ast.ArrayLiteral ) bool {
306310 for _ , row := range lit .Rows {
307311 for _ , cell := range row {
0 commit comments