-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Description
Nim Version
2.3.1
2.*
1.*
Description
import std/macros
macro items*(t: tuple): untyped =
result = newNimNode nnkBracket
if t.len != 0:
for i in t:
result.add i
else:
let nElem = t.getTypeImpl.len
if nElem == 0:
return parseExpr(
"items(array[0, int]([]))"
) # any type shall be ok
for i in 0..<nElem:
result.add nnkBracketExpr.newTree(t, newLit i)
result = newCall(ident"items", result)
type
Iterable*[T] = concept self ## Mimic Pythons Iterable. But not checks `iter`
for i in self: i is T
proc foo[T](it: Iterable[T]) =
for i in it: echo i
foo (1, 2)
Current Output
.......................................................................assertions.nim(34) raiseAssert
Error: unhandled exception: ccgexprs.nim(848, 3) `tupType.kind == tyTuple` [AssertionDefect]
Expected Output
1
2
Known Workarounds
No response
Additional Information
For JS backend, nim crashes with internalError:
Error: internal error: genFieldAddr
Metadata
Metadata
Assignees
Labels
No labels