mirror of
https://github.com/nim-lang/Nim.git
synced 2026-04-19 14:00:35 +00:00
void type for generics
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
13
tests/accept/compile/tvoid.nim
Normal file
13
tests/accept/compile/tvoid.nim
Normal 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]()
|
||||
|
||||
7
todo.txt
7
todo.txt
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user