This commit is contained in:
Araq
2014-12-28 01:59:30 +01:00
parent 03afbe00b9
commit f73938218e
7 changed files with 67 additions and 14 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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

View File

@@ -1,6 +1,7 @@
discard """
line: 12
errormsg: "instantiate 'notConcrete' explicitly"
disabled: "true"
"""
proc wrap[T]() =

View 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]

View File

@@ -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)

View File

@@ -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!
==============================