diff options
author | Araq <rumpf_a@web.de> | 2014-12-28 01:59:30 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-12-28 01:59:30 +0100 |
commit | f73938218ec39209ef1d898e26350e4828e1248c (patch) | |
tree | 111b2ebac9e08eee9b1b113677c7a3e48cace80b | |
parent | 03afbe00b99da07940adf143de1c2db5bf0c5336 (diff) | |
download | Nim-f73938218ec39209ef1d898e26350e4828e1248c.tar.gz |
fixes #1708, fixes #871
-rw-r--r-- | compiler/sem.nim | 20 | ||||
-rw-r--r-- | compiler/semexprs.nim | 5 | ||||
-rw-r--r-- | tests/misc/tcolonisproc.nim | 9 | ||||
-rw-r--r-- | tests/misc/tnoinst.nim | 1 | ||||
-rw-r--r-- | tests/types/temptyseqs.nim | 26 | ||||
-rw-r--r-- | tests/vm/tstringnil.nim | 2 | ||||
-rw-r--r-- | web/news.txt | 18 |
7 files changed, 67 insertions, 14 deletions
diff --git a/compiler/sem.nim b/compiler/sem.nim index 91adcac5e..9ac7ad139 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.. <a.len: + if isEmptyContainer(a.sons[i]) and not isEmptyContainer(b.sons[i]): + if nt.isNil: nt = copyType(a, a.owner, false) + nt.sons[i] = b.sons[i] + if not nt.isNil: result = nt #elif b.sons[idx].kind == tyEmpty: return x elif a.kind == tyRange and b.kind == tyRange: # consider: (range[0..3], range[0..4]) here. We should make that diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 25113aa5a..b11e8cb61 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -429,7 +429,8 @@ proc changeType(n: PNode, newType: PType, check: bool) = for i in countup(0, sonsLen(n) - 1): changeType(n.sons[i], elemType(newType), check) of nkPar: - if newType.kind != tyTuple: + let tup = newType.skipTypes({tyGenericInst}) + if tup.kind != tyTuple: internalError(n.info, "changeType: no tuple type for constructor") else: for i in countup(0, sonsLen(n) - 1): @@ -437,7 +438,7 @@ proc changeType(n: PNode, newType: PType, check: bool) = if m.kind == nkExprColonExpr: m = m.sons[1] n.sons[i] = m - changeType(m, newType.sons[i], check) + changeType(m, tup.sons[i], check) of nkCharLit..nkUInt64Lit: if check: let value = n.intVal diff --git a/tests/misc/tcolonisproc.nim b/tests/misc/tcolonisproc.nim index e55587dfc..af4077284 100644 --- a/tests/misc/tcolonisproc.nim +++ b/tests/misc/tcolonisproc.nim @@ -2,10 +2,11 @@ proc p(a, b: int, c: proc ()) = c() - -p(1, 3): - echo 1 - echo 3 +when false: + # language spec changed: + p(1, 3): + echo 1 + echo 3 p(1, 1, proc() = echo 1 diff --git a/tests/misc/tnoinst.nim b/tests/misc/tnoinst.nim index db1058d09..4c8d9d1aa 100644 --- a/tests/misc/tnoinst.nim +++ b/tests/misc/tnoinst.nim @@ -1,6 +1,7 @@ discard """ line: 12 errormsg: "instantiate 'notConcrete' explicitly" + disabled: "true" """ proc wrap[T]() = diff --git a/tests/types/temptyseqs.nim b/tests/types/temptyseqs.nim new file mode 100644 index 000000000..f8d22bdb8 --- /dev/null +++ b/tests/types/temptyseqs.nim @@ -0,0 +1,26 @@ +discard """ + output: "1" +""" + +# bug #1708 +let foo = { + "1" : (bar: @["1"]), + "2" : (baz: @[]) +} + +# bug #871 + +when true: + import os + + type + In_out = tuple[src, dest, options: string] + + let + nil_var: In_out = ("hey"/"there", "something", nil) + #nil_var2 = ("hey"/"there", "something", nil) + +# bug #1721 +const foo2: seq[string] = @[] + +echo foo[0][0][0] diff --git a/tests/vm/tstringnil.nim b/tests/vm/tstringnil.nim index 5070dd6b7..61ce60ee5 100644 --- a/tests/vm/tstringnil.nim +++ b/tests/vm/tstringnil.nim @@ -32,7 +32,7 @@ proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: PNimrodNode): tuple[tes testObj.testDesc = nil else: testObj.testDesc = child[2].strVal - testObj.testBlock = child[3][6] + testObj.testBlock = child[1] tests.add(testObj) diff --git a/web/news.txt b/web/news.txt index d1d23aebd..a2b3bdd4c 100644 --- a/web/news.txt +++ b/web/news.txt @@ -35,15 +35,17 @@ News What's left to be done ~~~~~~~~~~~~~~~~~~~~~~ - The 1.0 release is actually very close. There are only a couple of last - things that need to be done: + The 1.0 release is actually very close. Apart from bug fixes, there are + two major features missing or incomplete: - * Implementing static[T] properly - * Support for the overloading of the assignment operator + * ``static[T]`` needs to be defined precisely and the bugs in the + implementation need to be fixed. + * Overloading of the assignment operator is required for some generic + containers and needs to be implemented. + + This means that fancy matrix libraries will finally start to work, which used + to be a major point of pain in the language. - Of course, the 1.0 release is not an end to the development of Nim. - It is very much the beginning and we will be fleshing out the then - stable language. Nimble and other Nim tools ~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -191,6 +193,8 @@ News - User defined pragmas will now work for generics that have been instantiated in different modules. - Fixed queue exhaustion bug. + - Many, many more. + 2014-12-09 New website design! ============================== |