Skip to content

Commit

Permalink
spaghetti
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 16, 2024
1 parent cb7ed67 commit 6749f48
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
7 changes: 7 additions & 0 deletions compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,13 @@ const

proc semMacroExpr(c: PContext, n, nOrig: PNode, sym: PSym,
flags: TExprFlags = {}; expectedType: PType = nil): PNode =
if c.inGenericContext > 0 and sfAllUntyped notin sym.flags:
# in generic type body, typed macros can only be instantiated
# when the generic type is instantiated
result = semGenericStmt(c, n)
result.typ = makeTypeFromExpr(c, result.copyTree)
return

rememberExpansion(c, nOrig.info, sym)
pushInfoContext(c.config, nOrig.info, sym.detailedInfo)

Expand Down
6 changes: 5 additions & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -701,9 +701,13 @@ proc semResolvedCall(c: PContext, x: var TCandidate,
else:
c.inheritBindings(x, expectedType)
finalCallee = generateInstance(c, x.calleeSym, x.bindings, n.info)
else:
elif c.inGenericContext == 0:
# For macros and templates, the resolved generic params
# are added as normal params.
# This is not done in a generic type body context, as typed macros
# cannot be instantiated yet and semMacroExpr/semTemplateExpr will
# reject them and delay their instantiation, when fully resolved types
# will be added instead.
c.inheritBindings(x, expectedType)
for s in instantiateGenericParamList(c, gp, x.bindings):
case s.kind
Expand Down
7 changes: 7 additions & 0 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,13 @@ const

proc semTemplateExpr(c: PContext, n: PNode, s: PSym,
flags: TExprFlags = {}; expectedType: PType = nil): PNode =
if c.inGenericContext > 0 and sfAllUntyped notin s.flags:
# in generic type body, typed templates can only be instantiated
# when the generic type is instantiated
result = semGenericStmt(c, n)
result.typ = makeTypeFromExpr(c, result.copyTree)
return

rememberExpansion(c, n.info, s)
let info = getCallLineInfo(n)
markUsed(c, info, s)
Expand Down

0 comments on commit 6749f48

Please sign in to comment.