Skip to content

Commit

Permalink
fix #19426 compile error using when/elif/else and typedesc in template (
Browse files Browse the repository at this point in the history
  • Loading branch information
bung87 authored Oct 21, 2022
1 parent 5b195ab commit 04c48e3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/semfold.nim
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,7 @@ proc foldArrayAccess(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNo

proc foldFieldAccess(m: PSym, n: PNode; idgen: IdGenerator; g: ModuleGraph): PNode =
# a real field access; proc calls have already been transformed
if n[1].kind != nkSym: return nil
var x = getConstExpr(m, n[0], idgen, g)
if x == nil or x.kind notin {nkObjConstr, nkPar, nkTupleConstr}: return

Expand Down
16 changes: 16 additions & 0 deletions tests/whenstmt/t19426.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
type
MyInt = object
bitWidth: int

template toRealType*(t: MyInt): typedesc =
when t.bitWidth == 32: int32
elif t.bitWidth == 64: int64
else: {.error.}

proc doFail(T: typedesc): T = default(T)

proc test =
const myInt = MyInt(bitWidth:32)
discard doFail(toRealType(myInt))

test()

0 comments on commit 04c48e3

Please sign in to comment.