parent
59d19946c0
commit
e719f211c6
4 changed files with 37 additions and 3 deletions
|
|
@ -31,6 +31,15 @@ when declared(echo):
|
||||||
proc debug*(conf: ConfigRef; n: PType) {.deprecated.}
|
proc debug*(conf: ConfigRef; n: PType) {.deprecated.}
|
||||||
proc debug*(conf: ConfigRef; n: PNode) {.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.} =
|
template mdbg*: bool {.dirty.} =
|
||||||
when compiles(c.module):
|
when compiles(c.module):
|
||||||
c.module.fileIdx == c.config.projectMainIdx
|
c.module.fileIdx == c.config.projectMainIdx
|
||||||
|
|
|
||||||
|
|
@ -248,8 +248,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
resetIdTable(cl.symMap)
|
resetIdTable(cl.symMap)
|
||||||
resetIdTable(cl.localCache)
|
resetIdTable(cl.localCache)
|
||||||
|
|
||||||
# take a note of the original type. If't a free type parameter
|
# take a note of the original type. If't a free type or static parameter
|
||||||
# we'll need to keep it unbount for the `fitNode` operation below...
|
# we'll need to keep it unbound for the `fitNode` operation below...
|
||||||
var typeToFit = result[i]
|
var typeToFit = result[i]
|
||||||
|
|
||||||
let needsStaticSkipping = result[i].kind == tyFromExpr
|
let needsStaticSkipping = result[i].kind == tyFromExpr
|
||||||
|
|
@ -258,7 +258,8 @@ proc instantiateProcType(c: PContext, pt: TIdTable,
|
||||||
result[i] = result[i].skipTypes({tyStatic})
|
result[i] = result[i].skipTypes({tyStatic})
|
||||||
|
|
||||||
# ...otherwise, we use the instantiated type in `fitNode`
|
# ...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]
|
typeToFit = result[i]
|
||||||
|
|
||||||
internalAssert c.config, originalParams[i].kind == nkSym
|
internalAssert c.config, originalParams[i].kind == nkSym
|
||||||
|
|
|
||||||
|
|
@ -1056,6 +1056,9 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||||
if not containsGenericType(typ):
|
if not containsGenericType(typ):
|
||||||
# check type compatibility between def.typ and typ:
|
# check type compatibility between def.typ and typ:
|
||||||
def = fitNode(c, typ, def, def.info)
|
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 not hasType and not hasDefault:
|
||||||
if isType: localError(c.config, a.info, "':' expected")
|
if isType: localError(c.config, a.info, "':' expected")
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,11 @@
|
||||||
|
discard """
|
||||||
|
output: "1\n10\n1\n10"
|
||||||
|
nimout: '''
|
||||||
|
bar instantiated with 1
|
||||||
|
bar instantiated with 10
|
||||||
|
'''
|
||||||
|
"""
|
||||||
|
|
||||||
import typetraits
|
import typetraits
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -122,3 +130,16 @@ when true:
|
||||||
var p = getOrigin[float]()
|
var p = getOrigin[float]()
|
||||||
var rotated = p.rotate(2.1)
|
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)
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue