Skip to content

Commit

Permalink
better original patch + don't constant fold calls in typeof
Browse files Browse the repository at this point in the history
  • Loading branch information
metagn committed Aug 16, 2024
1 parent 6fa0c1c commit 399c7fd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
5 changes: 3 additions & 2 deletions compiler/semexprs.nim
Original file line number Diff line number Diff line change
Expand Up @@ -971,7 +971,7 @@ proc evalAtCompileTime(c: PContext, n: PNode): PNode =
if callee.magic notin ctfeWhitelist: return

if callee.kind notin {skProc, skFunc, skConverter, skConst} or
hasUnresolvedParams(n[0], {}):
callee.isGenericRoutineStrict:
return

if n.typ != nil and typeAllowed(n.typ, skConst, c) != nil: return
Expand Down Expand Up @@ -1119,7 +1119,8 @@ proc afterCallActions(c: PContext; n, orig: PNode, flags: TExprFlags; expectedTy
not (result.typ.kind == tySequence and result.elementType.kind == tyEmpty):
liftTypeBoundOps(c, result.typ, n.info)
#result = patchResolvedTypeBoundOp(c, result)
if c.matchedConcept == nil:
if c.matchedConcept == nil and efInTypeof notin flags:
# don't fold calls in concepts and typeof
result = evalAtCompileTime(c, result)

proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags; expectedType: PType = nil): PNode =
Expand Down
7 changes: 7 additions & 0 deletions tests/vm/tgenericcompiletimeproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ block: # issue #19365
proc f[T](x: static T): T {.compileTime.} = x + x
doAssert f(123) == 246
doAssert f(1.0) == 2.0

block:
# don't fold compile time procs in typeof
proc fail[T](x: T): T {.compileTime.} =
doAssert false
x
doAssert typeof(fail(123)) is typeof(123)

0 comments on commit 399c7fd

Please sign in to comment.