fix incorrect lenTuple implementation (#13423)

This commit is contained in:
Timothee Cour 2020-02-19 02:07:18 -08:00 • committed by GitHub
commit 273a93581f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 48 additions and 11 deletions

View file

@ -71,15 +71,14 @@ proc distinctBase*(T: typedesc): typedesc {.magic: "TypeTrait".}
## Returns base type for distinct types, works only for distinct types.
## compile time error otherwise
import std/macros
macro lenTuple*(t: tuple): int {.since: (1, 1).} =
## Return number of elements of `t`
newLit t.len
macro lenTuple*(t: typedesc[tuple]): int {.since: (1, 1).} =
proc lenTuple*(T: typedesc[tuple]): int {.magic: "TypeTrait", since: (1, 1).}
## Return number of elements of `T`
newLit t.len
since (1, 1):
template lenTuple*(t: tuple): int =
## Return number of elements of `t`
lenTuple(type(t))
since (1, 1):
template get*(T: typedesc[tuple], i: static int): untyped =
@ -87,6 +86,8 @@ since (1, 1):
# Note: `[]` currently gives: `Error: no generic parameters allowed for ...`
type(default(T)[i])
import std/macros
macro genericParams*(T: typedesc): untyped {.since: (1, 1).} =
## return tuple of generic params for generic `T`
runnableExamples: