diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 98f2950c90..de4ea2cc2b 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -724,7 +724,7 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp # nkBracket nodes can also be produced by the VM as seq constant nodes # in which case, we cannot produce a new array type for the node, # as this might lose type info even when the node has array type - let constructType = n.typ.isNil + let constructType = n.typ.isNil or n.typ.kind == tyFromExpr var expectedElementType, expectedIndexType: PType = nil var expectedBase: PType = nil if constructType: @@ -773,7 +773,11 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp let yy = semExprWithType(c, x, {efTypeAllowed}, expectedElementType) var typ: PType - if constructType: + var isGeneric = false + if yy.typ != nil and yy.typ.kind == tyFromExpr: + isGeneric = true + typ = nil # will not be used + elif constructType: typ = yy.typ if expectedElementType == nil: expectedElementType = typ @@ -798,11 +802,21 @@ proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags; expectedType: PTyp let xx = semExprWithType(c, x, {efTypeAllowed}, expectedElementType) result.add xx - if constructType: + if xx.typ != nil and xx.typ.kind == tyFromExpr: + isGeneric = true + elif constructType: typ = commonType(c, typ, xx.typ) #n[i] = semExprWithType(c, x, {}) #result.add fitNode(c, typ, n[i]) inc(lastIndex) + if isGeneric: + for i in 0..