Skip to content

Commit

Permalink
fixes #21326; getAst uses type info to annotateType quoted variables
Browse files Browse the repository at this point in the history
  • Loading branch information
ringabout committed Feb 24, 2023
1 parent 7dc80a7 commit 50d808e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2203,9 +2203,9 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
if ids.len > 0:
dummyTemplate[paramsPos] = newNodeI(nkFormalParams, n.info)
dummyTemplate[paramsPos].add getSysSym(c.graph, n.info, "untyped").newSymNode # return type
ids.add getSysSym(c.graph, n.info, "untyped").newSymNode # params type
ids.add c.graph.emptyNode # no default value
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids)
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[0], getSysSym(c.graph, n.info, "typed").newSymNode, c.graph.emptyNode)
for i in 1..<ids.len:
dummyTemplate[paramsPos].add newTreeI(nkIdentDefs, n.info, ids[i], getSysSym(c.graph, n.info, "typed").newSymNode, c.graph.emptyNode)

var tmpl = semTemplateDef(c, dummyTemplate)
quotes[0] = tmpl[namePos]
Expand All @@ -2223,6 +2223,10 @@ proc semQuoteAst(c: PContext, n: PNode): PNode =
newTreeI(nkCall, n.info, quotes))
result = semExpandToAst(c, result)

for i in 1..<ids.len:
tmpl[paramsPos][i+1][1] = newNodeIT(nkType, tmpl[paramsPos][i+1][1].info, result[1][i+1].typ)
discard semTemplateDef(c, tmpl)

proc tryExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode =
# watch out, hacks ahead:
when defined(nimsuggest):
Expand Down
5 changes: 4 additions & 1 deletion compiler/vm.nim
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
## This file implements the new evaluation engine for Nim code.
## An instruction is 1-3 int32s in memory, it is a register based VM.


import astalgo, semmacrosanity
import
std/[strutils, tables, parseutils],
msgs, vmdef, vmgen, nimsets, types, passes,
Expand Down Expand Up @@ -1408,6 +1408,9 @@ proc rawExecute(c: PCtx, start: int, tos: PStackFrame): TFullReg =
for i in 1..rc-1:
let node = regs[rb+i].regToNode
node.info = c.debug[pc]
if prc.typ[i].kind notin {tyTyped, tyUntyped}:
node.annotateType(prc.typ[i], c.config)

macroCall.add(node)
var a = evalTemplate(macroCall, prc, genSymOwner, c.config, c.cache, c.templInstCounter, c.idgen)
if a.kind == nkStmtList and a.len == 1: a = a[0]
Expand Down

0 comments on commit 50d808e

Please sign in to comment.