void type for generics

This commit is contained in:
Araq 2011-07-31 01:11:34 +02:00
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, GlobalError(n.info, errExprXHasNoType,
renderTree(result, {renderNoComments})) 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 = proc semSymGenericInstantiation(c: PContext, n: PNode, s: PSym): PNode =
result = symChoice(c, n, s) result = symChoice(c, n, s)

View file

@ -581,7 +581,11 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
addSon(result.n, newSymNode(arg)) addSon(result.n, newSymNode(arg))
addSon(result, typ) addSon(result, typ)
if n.sons[0].kind != nkEmpty: if n.sons[0].kind != nkEmpty:
result.sons[0] = paramType(c, n.sons[0], genericParams, cl) 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] res.typ = result.sons[0]
proc semStmtListType(c: PContext, n: PNode, prev: PType): PType = proc semStmtListType(c: PContext, n: PNode, prev: PType): PType =

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 * add ``modGet`` for generics
* documentation * documentation
* provide ``mod`` as an alternative syntax for ``var`` * 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 - optional indentation for 'case' statement
- make threadvar efficient again on linux after testing - make threadvar efficient again on linux after testing
- test the sort implementation again - test the sort implementation again

View file

@ -39,6 +39,8 @@ Language Additions
------------------ ------------------
- Added new ``is`` and ``of`` operators. - 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 Compiler Additions