diff options
-rw-r--r-- | compiler/sem.nim | 6 | ||||
-rw-r--r-- | compiler/semexprs.nim | 46 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 13 | ||||
-rw-r--r-- | tests/ccgbugs/tuple_canon.nim | 7 |
4 files changed, 20 insertions, 52 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index b713dbbbb..7768833b3 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -46,6 +46,10 @@ proc finishMethod(c: PContext, s: PSym) proc indexTypesMatch(c: PContext, f, a: PType, arg: PNode): PNode +proc isArrayConstr(n: PNode): bool {.inline.} = + result = n.kind == nkBracket and + n.typ.skipTypes(abstractInst).kind == tyArray + template semIdeForTemplateOrGenericCheck(n, requiresCheck) = # we check quickly if the node is where the cursor is when defined(nimsuggest): @@ -250,7 +254,7 @@ proc fixupTypeAfterEval(c: PContext, evaluated, eOrig: PNode): PNode = result = arg # for 'tcnstseq' we support [] to become 'seq' if eOrig.typ.skipTypes(abstractInst).kind == tySequence and - arg.typ.skipTypes(abstractInst).kind == tyArrayConstr: + isArrayConstr(arg): arg.typ = eOrig.typ proc tryConstExpr(c: PContext, n: PNode): PNode = diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 48af285bb..93d5ed1a2 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -409,7 +409,7 @@ proc changeType(n: PNode, newType: PType, check: bool) = n.typ = newType proc arrayConstrType(c: PContext, n: PNode): PType = - var typ = newTypeS(tyArrayConstr, c) + var typ = newTypeS(tyArray, c) rawAddSon(typ, nil) # index type if sonsLen(n) == 0: rawAddSon(typ, newTypeS(tyEmpty, c)) # needs an empty basetype! @@ -421,7 +421,7 @@ proc arrayConstrType(c: PContext, n: PNode): PType = proc semArrayConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = result = newNodeI(nkBracket, n.info) - result.typ = newTypeS(tyArrayConstr, c) + result.typ = newTypeS(tyArray, c) rawAddSon(result.typ, nil) # index type if sonsLen(n) == 0: rawAddSon(result.typ, newTypeS(tyEmpty, c)) # needs an empty basetype! @@ -466,49 +466,11 @@ proc fixAbstractType(c: PContext, n: PNode) = if it.kind == nkHiddenSubConv and skipTypes(it.typ, abstractVar).kind notin {tyOpenArray, tyVarargs}: if skipTypes(it.sons[1].typ, abstractVar).kind in - {tyNil, tyArrayConstr, tyTuple, tySet}: + {tyNil, tyTuple, tySet} or it[1].isArrayConstr: var s = skipTypes(it.typ, abstractVar) if s.kind != tyExpr: changeType(it.sons[1], s, check=true) n.sons[i] = it.sons[1] - when false: - # XXX finally rewrite that crap! - for i in countup(1, sonsLen(n) - 1): - var it = n.sons[i] - case it.kind - of nkHiddenStdConv, nkHiddenSubConv: - if it.sons[1].kind == nkBracket: - it.sons[1].typ = arrayConstrType(c, it.sons[1]) - #it.sons[1] = semArrayConstr(c, it.sons[1]) - if skipTypes(it.typ, abstractVar).kind in {tyOpenArray, tyVarargs}: - #if n.sons[0].kind == nkSym and IdentEq(n.sons[0].sym.name, "[]="): - # debug(n) - - var s = skipTypes(it.sons[1].typ, abstractVar) - if s.kind == tyArrayConstr and s.sons[1].kind == tyEmpty: - s = copyType(s, getCurrOwner(), false) - skipTypes(s, abstractVar).sons[1] = elemType( - skipTypes(it.typ, abstractVar)) - it.sons[1].typ = s - elif s.kind == tySequence and s.sons[0].kind == tyEmpty: - s = copyType(s, getCurrOwner(), false) - skipTypes(s, abstractVar).sons[0] = elemType( - skipTypes(it.typ, abstractVar)) - it.sons[1].typ = s - - elif skipTypes(it.sons[1].typ, abstractVar).kind in - {tyNil, tyArrayConstr, tyTuple, tySet}: - var s = skipTypes(it.typ, abstractVar) - if s.kind != tyExpr: - changeType(it.sons[1], s, check=true) - n.sons[i] = it.sons[1] - of nkBracket: - # an implicitly constructed array (passed to an open array): - n.sons[i] = semArrayConstr(c, it, {}) - else: - discard - #if (it.typ == nil): - # InternalError(it.info, "fixAbstractType: " & renderTree(it)) proc isAssignable(c: PContext, n: PNode; isUnsafeAddr=false): TAssignableResult = result = parampatterns.isAssignable(c.p.owner, n, isUnsafeAddr) @@ -968,7 +930,7 @@ proc semSym(c: PContext, n: PNode, s: PSym, flags: TExprFlags): PNode = tyTuple, tySet, tyUInt..tyUInt64: if s.magic == mNone: result = inlineConst(n, s) else: result = newSymNode(s, n.info) - of tyArrayConstr, tySequence: + of tyArray, tySequence: # Consider:: # const x = [] # proc p(a: openarray[int]) diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 90435f9c0..b8dfede1f 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -850,12 +850,7 @@ proc typeRel(c: var TCandidate, f, aOrig: PType, doBind = true): TTypeRelation = of tyOpenArray, tyVarargs: result = typeRel(c, base(f), base(a)) if result < isGeneric: result = isNone - of tyArrayConstr: - if (f.sons[0].kind != tyGenericParam) and (a.sons[1].kind == tyEmpty): - result = isSubtype # [] is allowed here - elif typeRel(c, base(f), a.sons[1]) >= isGeneric: - result = isSubtype - of tyArray: + of tyArray, tyArrayConstr: if (f.sons[0].kind != tyGenericParam) and (a.sons[1].kind == tyEmpty): result = isSubtype elif typeRel(c, base(f), a.sons[1]) >= isGeneric: @@ -1604,17 +1599,17 @@ proc prepareNamedParam(a: PNode) = a.sons[0] = newIdentNode(considerQuotedIdent(a.sons[0]), info) proc arrayConstr(c: PContext, n: PNode): PType = - result = newTypeS(tyArrayConstr, c) + result = newTypeS(tyArray, c) rawAddSon(result, makeRangeType(c, 0, 0, n.info)) addSonSkipIntLit(result, skipTypes(n.typ, {tyGenericInst, tyVar, tyOrdinal})) proc arrayConstr(c: PContext, info: TLineInfo): PType = - result = newTypeS(tyArrayConstr, c) + result = newTypeS(tyArray, c) rawAddSon(result, makeRangeType(c, 0, -1, info)) rawAddSon(result, newTypeS(tyEmpty, c)) # needs an empty basetype! proc incrIndexType(t: PType) = - assert t.kind == tyArrayConstr + assert t.kind == tyArray inc t.sons[0].n.sons[1].intVal template isVarargsUntyped(x): untyped = diff --git a/tests/ccgbugs/tuple_canon.nim b/tests/ccgbugs/tuple_canon.nim index 960e2aae9..a607f9cab 100644 --- a/tests/ccgbugs/tuple_canon.nim +++ b/tests/ccgbugs/tuple_canon.nim @@ -1,3 +1,10 @@ + + +# bug #4626 +var foo: (int, array[1, int]) # Tuple must be of length > 1 +let bar = (1, [1]) +foo = bar # No error if assigned directly + # bug #2250 import |