From 6c752274fb7730b6c0ccb57f5810bf9bdb7e5c4e Mon Sep 17 00:00:00 2001 From: hlaaftana <10591326+metagn@users.noreply.github.com> Date: Mon, 15 Aug 2022 06:32:10 +0300 Subject: [PATCH] add documentation, support templates --- compiler/sem.nim | 4 +- compiler/semexprs.nim | 37 ++++++------ doc/manual_experimental.md | 58 +++++++++++++++++++ ...dedinference.nim => ttopdowninference.nim} | 14 ++++- 4 files changed, 92 insertions(+), 21 deletions(-) rename tests/types/{textendedinference.nim => ttopdowninference.nim} (93%) diff --git a/compiler/sem.nim b/compiler/sem.nim index f09b5a31c716c..8fac158bae96a 100644 --- a/compiler/sem.nim +++ b/compiler/sem.nim @@ -269,10 +269,10 @@ proc paramsTypeCheck(c: PContext, typ: PType) {.inline.} = typeAllowedCheck(c, typ.n.info, typ, skProc) proc expectMacroOrTemplateCall(c: PContext, n: PNode): PSym -proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode +proc semDirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode proc semWhen(c: PContext, n: PNode, semCheck: bool = true): PNode proc semTemplateExpr(c: PContext, n: PNode, s: PSym, - flags: TExprFlags = {}): PNode + flags: TExprFlags = {}; expectedType: PType = nil): PNode proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym, flags: TExprFlags = {}; expectedType: PType = nil): PNode diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 233c7be51b16c..173bf05972b6a 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -26,7 +26,7 @@ const errUndeclaredFieldX = "undeclared field: '$1'" proc semTemplateExpr(c: PContext, n: PNode, s: PSym, - flags: TExprFlags = {}): PNode = + flags: TExprFlags = {}; expectedType: PType = nil): PNode = rememberExpansion(c, n.info, s) let info = getCallLineInfo(n) markUsed(c, info, s) @@ -36,7 +36,8 @@ proc semTemplateExpr(c: PContext, n: PNode, s: PSym, pushInfoContext(c.config, n.info, s.detailedInfo) result = evalTemplate(n, s, getCurrOwner(c), c.config, c.cache, c.templInstCounter, c.idgen, efFromHlo in flags) - if efNoSemCheck notin flags: result = semAfterMacroCall(c, n, result, s, flags) + if efNoSemCheck notin flags: + result = semAfterMacroCall(c, n, result, s, flags, expectedType) popInfoContext(c.config) # XXX: A more elaborate line info rewrite might be needed @@ -940,15 +941,15 @@ proc setGenericParams(c: PContext, n: PNode) = for i in 1..