Skip to content

Commit

Permalink
make getUnderlyingType work with type argument
Browse files Browse the repository at this point in the history
Below `newStorage[T]` and `newStorageOfCap[T]` call `getUnderlyingType(T)`, which shouldn't work because `T` is a type and `getUnderlyingType` takes an `openArray` argument. However it works due to a [Nim bug](nim-lang/Nim#20033) where `T` is treated as a *value* of its type.

To make this work with and without the bug fixed, add an additional `getUnderlyingType` overload that takes a `type openArray` parameter instead.
  • Loading branch information
metagn authored Aug 23, 2023
1 parent 82cfffd commit 87f6857
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions nimPNG.nim
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ proc crc32(crc: uint32, buf: string): uint32 =
result = not crcu32

template getUnderlyingType[T](_: openArray[T]): untyped = T
template getUnderlyingType[T](_: type openArray[T]): untyped = T

template newStorage[T](size: int): auto =
when T is string:
Expand Down

0 comments on commit 87f6857

Please sign in to comment.