void type for generics

This commit is contained in:
Araq
2011-07-31 01:11:34 +02:00
parent 05cffb9370
commit 00da785f5d
5 changed files with 27 additions and 13 deletions

View File

@@ -36,16 +36,6 @@ proc semExprWithType(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
GlobalError(n.info, errExprXHasNoType,
renderTree(result, {renderNoComments}))
proc semExprWithTypeNoDeref(c: PContext, n: PNode,
flags: TExprFlags = {}): PNode =
result = semExpr(c, n, flags)
if result.kind == nkEmpty:
# do not produce another redundant error message:
raiseRecoverableError()
if result.typ == nil:
GlobalError(n.info, errExprXHasNoType,
renderTree(result, {renderNoComments}))
proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
result = symChoice(c, n, s)

View File

@@ -581,8 +581,12 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
addSon(result.n, newSymNode(arg))
addSon(result, typ)
if n.sons[0].kind != nkEmpty:
result.sons[0] = paramType(c, n.sons[0], genericParams, cl)
res.typ = result.sons[0]
var r = paramType(c, n.sons[0], genericParams, cl)
# turn explicit 'void' return type into 'nil' because the rest of the
# compiler only checks for 'nil':
if skipTypes(r, {tyGenericInst}).kind != tyEmpty:
result.sons[0] = r
res.typ = result.sons[0]
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =
checkMinSonsLen(n, 1)

View File

@@ -0,0 +1,13 @@
discard """
output: "he, no return type; a string"
"""
proc ReturnT[T](): T =
when T is void:
echo "he, no return type;"
else:
result = " a string"
ReturnT[void]()
echo ReturnT[string]()

View File

@@ -6,7 +6,12 @@ Version 0.8.14
* add ``modGet`` for generics
* documentation
* provide ``mod`` as an alternative syntax for ``var``
- document Nimrod's two phase symbol lookup for generics
- document:
* Nimrod's two phase symbol lookup in generics
* type constraints for generics
* void type
* ``is`` operator for type equivalence
- optional indentation for 'case' statement
- make threadvar efficient again on linux after testing
- test the sort implementation again

View File

@@ -39,6 +39,8 @@ Language Additions
------------------
- Added new ``is`` and ``of`` operators.
- The built-in type ``void`` can be used to denote the absense of any type.
This is only needed in generic contexts.
Compiler Additions