parent
03afbe00b9
commit
f73938218e
7 changed files with 67 additions and 14 deletions
|
|
@ -67,12 +67,25 @@ proc fitNode(c: PContext, formal: PType, arg: PNode): PNode =
|
||||||
# error correction:
|
# error correction:
|
||||||
result = copyTree(arg)
|
result = copyTree(arg)
|
||||||
result.typ = formal
|
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,
|
proc inferWithMetatype(c: PContext, formal: PType,
|
||||||
arg: PNode, coerceDistincts = false): PNode
|
arg: PNode, coerceDistincts = false): PNode
|
||||||
|
|
||||||
var commonTypeBegin = PType(kind: tyExpr)
|
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 =
|
proc commonType*(x, y: PType): PType =
|
||||||
# new type relation that is used for array constructors,
|
# new type relation that is used for array constructors,
|
||||||
# if expressions, etc.:
|
# if expressions, etc.:
|
||||||
|
|
@ -96,6 +109,13 @@ proc commonType*(x, y: PType): PType =
|
||||||
# check for seq[empty] vs. seq[int]
|
# check for seq[empty] vs. seq[int]
|
||||||
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
let idx = ord(b.kind in {tyArray, tyArrayConstr})
|
||||||
if a.sons[idx].kind == tyEmpty: return y
|
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 b.sons[idx].kind == tyEmpty: return x
|
||||||
elif a.kind == tyRange and b.kind == tyRange:
|
elif a.kind == tyRange and b.kind == tyRange:
|
||||||
# consider: (range[0..3], range[0..4]) here. We should make that
|
# consider: (range[0..3], range[0..4]) here. We should make that
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,8 @@ proc changeType(n: PNode, newType: PType, check: bool) =
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
changeType(n.sons[i], elemType(newType), check)
|
changeType(n.sons[i], elemType(newType), check)
|
||||||
of nkPar:
|
of nkPar:
|
||||||
if newType.kind != tyTuple:
|
let tup = newType.skipTypes({tyGenericInst})
|
||||||
|
if tup.kind != tyTuple:
|
||||||
internalError(n.info, "changeType: no tuple type for constructor")
|
internalError(n.info, "changeType: no tuple type for constructor")
|
||||||
else:
|
else:
|
||||||
for i in countup(0, sonsLen(n) - 1):
|
for i in countup(0, sonsLen(n) - 1):
|
||||||
|
|
@ -437,7 +438,7 @@ proc changeType(n: PNode, newType: PType, check: bool) =
|
||||||
if m.kind == nkExprColonExpr:
|
if m.kind == nkExprColonExpr:
|
||||||
m = m.sons[1]
|
m = m.sons[1]
|
||||||
n.sons[i] = m
|
n.sons[i] = m
|
||||||
changeType(m, newType.sons[i], check)
|
changeType(m, tup.sons[i], check)
|
||||||
of nkCharLit..nkUInt64Lit:
|
of nkCharLit..nkUInt64Lit:
|
||||||
if check:
|
if check:
|
||||||
let value = n.intVal
|
let value = n.intVal
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,11 @@
|
||||||
proc p(a, b: int, c: proc ()) =
|
proc p(a, b: int, c: proc ()) =
|
||||||
c()
|
c()
|
||||||
|
|
||||||
|
when false:
|
||||||
p(1, 3):
|
# language spec changed:
|
||||||
echo 1
|
p(1, 3):
|
||||||
echo 3
|
echo 1
|
||||||
|
echo 3
|
||||||
|
|
||||||
p(1, 1, proc() =
|
p(1, 1, proc() =
|
||||||
echo 1
|
echo 1
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
discard """
|
discard """
|
||||||
line: 12
|
line: 12
|
||||||
errormsg: "instantiate 'notConcrete' explicitly"
|
errormsg: "instantiate 'notConcrete' explicitly"
|
||||||
|
disabled: "true"
|
||||||
"""
|
"""
|
||||||
|
|
||||||
proc wrap[T]() =
|
proc wrap[T]() =
|
||||||
|
|
|
||||||
26
tests/types/temptyseqs.nim
Normal file
26
tests/types/temptyseqs.nim
Normal file
|
|
@ -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]
|
||||||
|
|
@ -32,7 +32,7 @@ proc buildSuiteContents(suiteName, suiteDesc, suiteBloc: PNimrodNode): tuple[tes
|
||||||
testObj.testDesc = nil
|
testObj.testDesc = nil
|
||||||
else:
|
else:
|
||||||
testObj.testDesc = child[2].strVal
|
testObj.testDesc = child[2].strVal
|
||||||
testObj.testBlock = child[3][6]
|
testObj.testBlock = child[1]
|
||||||
|
|
||||||
tests.add(testObj)
|
tests.add(testObj)
|
||||||
|
|
||||||
|
|
|
||||||
18
web/news.txt
18
web/news.txt
|
|
@ -35,15 +35,17 @@ News
|
||||||
What's left to be done
|
What's left to be done
|
||||||
~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
||||||
The 1.0 release is actually very close. There are only a couple of last
|
The 1.0 release is actually very close. Apart from bug fixes, there are
|
||||||
things that need to be done:
|
two major features missing or incomplete:
|
||||||
|
|
||||||
* Implementing static[T] properly
|
* ``static[T]`` needs to be defined precisely and the bugs in the
|
||||||
* Support for the overloading of the assignment operator
|
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
|
Nimble and other Nim tools
|
||||||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||||
|
|
@ -191,6 +193,8 @@ News
|
||||||
- User defined pragmas will now work for generics that have
|
- User defined pragmas will now work for generics that have
|
||||||
been instantiated in different modules.
|
been instantiated in different modules.
|
||||||
- Fixed queue exhaustion bug.
|
- Fixed queue exhaustion bug.
|
||||||
|
- Many, many more.
|
||||||
|
|
||||||
|
|
||||||
2014-12-09 New website design!
|
2014-12-09 New website design!
|
||||||
==============================
|
==============================
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue