Skip to content

Commit

Permalink
allow early template macro instantiation? weird territory
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 17, 2024
1 parent 1a10692 commit 3fd21cd
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion compiler/sem.nim
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ 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:
if false and 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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/semcall.nim
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ proc semResolvedCall(c: PContext, x: var TCandidate,
else:
c.inheritBindings(x, expectedType)
finalCallee = generateInstance(c, x.calleeSym, x.bindings, n.info)
elif c.inGenericContext == 0:
elif true or 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
Expand Down
2 changes: 1 addition & 1 deletion compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ const

proc semTemplateExpr(c: PContext, n: PNode, s: PSym,
flags: TExprFlags = {}; expectedType: PType = nil): PNode =
if c.inGenericContext > 0 and sfAllUntyped notin s.flags:
if false and 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)
Expand Down
12 changes: 12 additions & 0 deletions tests/generics/tuninstantiatedgenericcalls.nim
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,15 @@ block: # deref syntax
doAssert foo.x == 123
inc foo.x
doAssert foo.x == 124

block:
type Generic[T] = object
field: T
macro foo(x: typed): untyped = x
type Foo[T] = object
field: Generic[int].foo()
var x: Foo[int]
macro bar[T](x: typedesc[Generic[T]]): untyped = x
type Bar[T] = object
field: Generic[int].bar()
var y: Bar[int]

0 comments on commit 3fd21cd

Please sign in to comment.