This commit is contained in:
Zahary Karadjov
2018-06-14 12:47:07 +03:00
parent 59d19946c0
commit e719f211c6
4 changed files with 37 additions and 3 deletions

View File

@@ -31,6 +31,15 @@ when declared(echo):
proc debug*(conf: ConfigRef; n: PType) {.deprecated.}
proc debug*(conf: ConfigRef; n: PNode) {.deprecated.}
template debug*(x: PSym|PType|PNode) {.deprecated.} =
when compiles(c.config):
debug(c.config, x)
else:
error()
template debug*(x: auto) {.deprecated.} =
echo x
template mdbg*: bool {.dirty.} =
when compiles(c.module):
c.module.fileIdx == c.config.projectMainIdx

View File

@@ -248,8 +248,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
resetIdTable(cl.symMap)
resetIdTable(cl.localCache)
# take a note of the original type. If't a free type parameter
# we'll need to keep it unbount for the `fitNode` operation below...
# take a note of the original type. If't a free type or static parameter
# we'll need to keep it unbound for the `fitNode` operation below...
var typeToFit = result[i]
let needsStaticSkipping = result[i].kind == tyFromExpr
@@ -258,7 +258,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
result[i] = result[i].skipTypes({tyStatic})
# ...otherwise, we use the instantiated type in `fitNode`
if typeToFit.kind != tyTypeDesc or typeToFit.base.kind != tyNone:
if (typeToFit.kind != tyTypeDesc or typeToFit.base.kind != tyNone) and
(typeToFit.kind != tyStatic):
typeToFit = result[i]
internalAssert c.config, originalParams[i].kind == nkSym

View File

@@ -1056,6 +1056,9 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
if not containsGenericType(typ):
# check type compatibility between def.typ and typ:
def = fitNode(c, typ, def, def.info)
elif typ.kind == tyStatic:
def = semConstExpr(c, def)
def = fitNode(c, typ, def, def.info)
if not hasType and not hasDefault:
if isType: localError(c.config, a.info, "':' expected")

View File

@@ -1,3 +1,11 @@
discard """
output: "1\n10\n1\n10"
nimout: '''
bar instantiated with 1
bar instantiated with 10
'''
"""
import typetraits
type
@@ -122,3 +130,16 @@ when true:
var p = getOrigin[float]()
var rotated = p.rotate(2.1)
test 7:
proc bar(x: static[int]) =
static: echo "bar instantiated with ", x
echo x
proc foo(x: static[int] = 1) =
bar(x)
foo()
foo(10)
foo(1)
foo(10)