diff options
author | Araq <rumpf_a@web.de> | 2015-01-18 02:33:28 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2015-01-18 02:33:44 +0100 |
commit | abb738146aea1b9692362bf8048ca23a93bd9fa5 (patch) | |
tree | dc5c498ed813ca7ab80ad5ae45bae8abb02f1e6f /compiler | |
parent | a2b7e6c3925f1320fe178b135fa3d64c62c3e5ef (diff) | |
download | Nim-abb738146aea1b9692362bf8048ca23a93bd9fa5.tar.gz |
revert to old behaviour: tuple field names are not ignored anymore; fixes #1920
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/semexprs.nim | 18 | ||||
-rw-r--r-- | compiler/sigmatch.nim | 2 | ||||
-rw-r--r-- | compiler/types.nim | 9 |
3 files changed, 25 insertions, 4 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index a3ae0263d..8f958c9bf 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -439,12 +439,24 @@ proc changeType(n: PNode, newType: PType, check: bool) = let tup = newType.skipTypes({tyGenericInst}) if tup.kind != tyTuple: internalError(n.info, "changeType: no tuple type for constructor") + elif newType.n == nil: discard + elif sonsLen(n) > 0 and n.sons[0].kind == nkExprColonExpr: + for i in countup(0, sonsLen(n) - 1): + var m = n.sons[i].sons[0] + if m.kind != nkSym: + internalError(m.info, "changeType(): invalid tuple constr") + return + var f = getSymFromList(newType.n, m.sym.name) + if f == nil: + internalError(m.info, "changeType(): invalid identifier") + return + changeType(n.sons[i].sons[1], f.typ, check) else: for i in countup(0, sonsLen(n) - 1): var m = n.sons[i] - if m.kind == nkExprColonExpr: - m = m.sons[1] - n.sons[i] = m + var a = newNodeIT(nkExprColonExpr, m.info, newType.sons[i]) + addSon(a, newSymNode(newType.n.sons[i].sym)) + addSon(a, m) changeType(m, tup.sons[i], check) of nkCharLit..nkUInt64Lit: if check: diff --git a/compiler/sigmatch.nim b/compiler/sigmatch.nim index 3c6cd248e..549f1f9ad 100644 --- a/compiler/sigmatch.nim +++ b/compiler/sigmatch.nim @@ -357,7 +357,7 @@ proc recordRel(c: var TCandidate, f, a: PType): TTypeRelation = var y = a.n.sons[i].sym if f.kind == tyObject and typeRel(c, x.typ, y.typ) < isSubtype: return isNone - if x.name.id != y.name.id and f.kind != tyTuple: return isNone + if x.name.id != y.name.id: return isNone proc allowsNil(f: PType): TTypeRelation {.inline.} = result = if tfNotNil notin f.flags: isSubtype else: isNone diff --git a/compiler/types.nim b/compiler/types.nim index a07698012..e7841a9ab 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -781,6 +781,15 @@ proc sameTuple(a, b: PType, c: var TSameTypeClosure): bool = result = sameTypeAux(x, y, c) if not result: return + if a.n != nil and b.n != nil and IgnoreTupleFields notin c.flags: + for i in countup(0, sonsLen(a.n) - 1): + # check field names: + if a.n.sons[i].kind == nkSym and b.n.sons[i].kind == nkSym: + var x = a.n.sons[i].sym + var y = b.n.sons[i].sym + result = x.name.id == y.name.id + if not result: break + else: internalError(a.n.info, "sameTuple") template ifFastObjectTypeCheckFailed(a, b: PType, body: stmt) {.immediate.} = if tfFromGeneric notin a.flags + b.flags: |