From f73938218ec39209ef1d898e26350e4828e1248c Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 28 Dec 2014 01:59:30 +0100 Subject: [PATCH] fixes #1708, fixes #871 --- compiler/sem.nim | 20 ++++++++++++++++++++ compiler/semexprs.nim | 5 +++-- tests/misc/tcolonisproc.nim | 9 +++++---- tests/misc/tnoinst.nim | 1 + tests/types/temptyseqs.nim | 26 ++++++++++++++++++++++++++ tests/vm/tstringnil.nim | 2 +- web/news.txt | 18 +++++++++++------- 7 files changed, 67 insertions(+), 14 deletions(-) create mode 100644 tests/types/temptyseqs.nim diff --git a/compiler/sem.nim b/compiler/sem.nim index 91adcac5ee..9ac7ad1390 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -67,12 +67,25 @@ proc fitNode(c: PContext, formal: PType, arg: PNode): PNode = # error correction: result = copyTree(arg) result.typ = formal + else: + let x = result.skipConv + if x.kind == nkPar and formal.kind != tyExpr: + changeType(x, formal, check=true) proc inferWithMetatype(c: PContext, formal: PType, arg: PNode, coerceDistincts = false): PNode var commonTypeBegin = PType(kind: tyExpr) +proc isEmptyContainer(t: PType): bool = + case t.kind + of tyExpr, tyNil: result = true + of tyArray, tyArrayConstr: result = t.sons[1].kind == tyEmpty + of tySet, tySequence, tyOpenArray, tyVarargs: + result = t.sons[0].kind == tyEmpty + of tyGenericInst: result = isEmptyContainer(t.lastSon) + else: result = false + proc commonType*(x, y: PType): PType = # new type relation that is used for array constructors, # if expressions, etc.: @@ -96,6 +109,13 @@ proc commonType*(x, y: PType): PType = # check for seq[empty] vs. seq[int] let idx = ord(b.kind in {tyArray, tyArrayConstr}) if a.sons[idx].kind == tyEmpty: return y + elif a.kind == tyTuple and b.kind == tyTuple and a.len == b.len: + var nt: PType + for i in 0..