mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-09 06:23:25 +00:00
proc arguments are in scope when the result type definition is being processed
This is intended for type deduction depending on the arguments proc foo(x: type): type(expr(x))
This commit is contained in:
@@ -135,7 +135,8 @@ proc generateInstance(c: PContext, fn: PSym, pt: TIdTable,
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
removeDefaultParamValues(n.sons[ParamsPos])
|
||||
semParamList(c, n.sons[ParamsPos], nil, result)
|
||||
addParams(c, result.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList #
|
||||
# addParams(c, result.typ.n)
|
||||
else:
|
||||
result.typ = newTypeS(tyProc, c)
|
||||
addSon(result.typ, nil)
|
||||
|
||||
@@ -616,7 +616,8 @@ proc semLambda(c: PContext, n: PNode): PNode =
|
||||
illFormedAst(n) # process parameters:
|
||||
if n.sons[paramsPos].kind != nkEmpty:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
addParams(c, s.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList
|
||||
# addParams(c, s.typ.n)
|
||||
ParamsTypeCheck(c, s.typ)
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
@@ -665,7 +666,8 @@ proc semProcAux(c: PContext, n: PNode, kind: TSymKind,
|
||||
n.sons[genericParamsPos] = gp
|
||||
# check for semantics again:
|
||||
semParamList(c, n.sons[ParamsPos], nil, s)
|
||||
addParams(c, s.typ.n)
|
||||
# XXX: obsoleted - happens in semParamList
|
||||
# addParams(c, s.typ.n)
|
||||
else:
|
||||
s.typ = newTypeS(tyProc, c)
|
||||
addSon(s.typ, nil)
|
||||
|
||||
@@ -185,7 +185,8 @@ proc semTemplateDef(c: PContext, n: PNode): PNode =
|
||||
# use ``stmt`` as implicit result type
|
||||
s.typ.sons[0] = newTypeS(tyStmt, c)
|
||||
s.typ.n.sons[0] = newNodeIT(nkType, n.info, s.typ.sons[0])
|
||||
addParams(c, s.typ.n) # resolve parameters:
|
||||
# XXX: obsoleted - happens in semParamList #
|
||||
# addParams(c, s.typ.n) # resolve parameters:
|
||||
var toBind = initIntSet()
|
||||
n.sons[bodyPos] = resolveTemplateParams(c, n.sons[bodyPos], false, toBind)
|
||||
if s.typ.sons[0].kind notin {tyStmt, tyTypeDesc}:
|
||||
|
||||
@@ -569,6 +569,8 @@ proc semProcTypeNode(c: PContext, n, genericParams: PNode,
|
||||
LocalError(a.sons[j].info, errAttemptToRedefine, arg.name.s)
|
||||
addSon(result.n, newSymNode(arg))
|
||||
addSon(result, typ)
|
||||
addDecl(c, arg)
|
||||
|
||||
if n.sons[0].kind != nkEmpty:
|
||||
var r = paramType(c, n.sons[0], genericParams, cl)
|
||||
# turn explicit 'void' return type into 'nil' because the rest of the
|
||||
@@ -711,11 +713,13 @@ proc semTypeNode(c: PContext, n: PNode, prev: PType): PType =
|
||||
of nkDistinctTy: result = semDistinct(c, n, prev)
|
||||
of nkProcTy:
|
||||
checkSonsLen(n, 2)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||
openScope(c.tab)
|
||||
result = semProcTypeNode(c, n.sons[0], nil, prev)
|
||||
# dummy symbol for `pragma`:
|
||||
var s = newSymS(skProc, newIdentNode(getIdent("dummy"), n.info), c)
|
||||
s.typ = result
|
||||
pragma(c, s, n.sons[1], procTypePragmas)
|
||||
closeScope(c.tab)
|
||||
of nkEnumTy: result = semEnum(c, n, prev)
|
||||
of nkType: result = n.typ
|
||||
of nkStmtListType: result = semStmtListType(c, n, prev)
|
||||
|
||||
@@ -35,3 +35,6 @@ var y*: type(t2(100)) = "test"
|
||||
proc t6*(x: type(t3(0))): type(t1(0)) =
|
||||
result = $x
|
||||
|
||||
proc t7*(x: int): type($x) =
|
||||
result = "test"
|
||||
|
||||
|
||||
Reference in New Issue
Block a user