You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This code works only if you replace cache.order with items(cache.order). Title may not be fully correct so feel free to edit it. Found by @PMunch in their https://github.com/PMunch/nim-cache project
Example
# a.nimtypeData[T] =object
data: seq[T]
Cache*[X: static[int]] =refobject
order: Data[string]
iteratoritems[T](x: Data[T]): T =for x in x.data:
yield x
procinitCache*[X: static[int]](): Cache[X] =Cache[X](order: Data[string](data: @["hello"]))
iteratoritems*[X: static[int]](cache: Cache[X]): string=# works if you replace cache.order with items(cache.order)for item in cache.order:
yield item
# b.nimimport a
var c =initCache[5]()
for entry in c:
echo entry
Current Output
/home/dian/Projects/nim-mathexpr/nim-cache/a.nim(17, 20) Error: type mismatch: got <Data[system.string]>
but expected one of:
iterator items(E: typedesc[enum]): E:type
first type mismatch at position: 1
required type for E: type enum
but expression 'cache.order' is of type: Data[system.string]
iterator items(a: cstring): char
first type mismatch at position: 1
required type for a: cstring
but expression 'cache.order' is of type: Data[system.string]
iterator items(a: string): char
first type mismatch at position: 1
required type for a: string
but expression 'cache.order' is of type: Data[system.string]
iterator items[IX, T](a: array[IX, T]): T
first type mismatch at position: 1
required type for a: array[IX, T]
but expression 'cache.order' is of type: Data[system.string]
iterator items[T](a: openArray[T]): T
first type mismatch at position: 1
required type for a: openArray[T]
but expression 'cache.order' is of type: Data[system.string]
iterator items[T](a: seq[T]): T
first type mismatch at position: 1
required type for a: seq[T]
but expression 'cache.order' is of type: Data[system.string]
iterator items[T](a: set[T]): T
first type mismatch at position: 1
required type for a: set[T]
but expression 'cache.order' is of type: Data[system.string]
iterator items[T](s: HSlice[T, T]): T
first type mismatch at position: 1
required type for s: HSlice[items.T, items.T]
but expression 'cache.order' is of type: Data[system.string]
iterator items[X: static[int]](cache: Cache[X]): string
first type mismatch at position: 1
required type for cache: Cache[items.X]
but expression 'cache.order' is of type: Data[system.string]
expression: items(cache.order)
Expected Output
hello
Nim Compiler Version 1.3.5 [Linux: amd64]
Compiled at 2020-05-26
Copyright (c) 2006-2020 by Andreas Rumpf
git hash: dadc97d91e6ece6387195bdaad54baa9d3f0fc12
active boot switches: -d:release
The text was updated successfully, but these errors were encountered:
This code works only if you replace
cache.order
withitems(cache.order)
. Title may not be fully correct so feel free to edit it. Found by @PMunch in their https://github.com/PMunch/nim-cache projectExample
Current Output
Expected Output
The text was updated successfully, but these errors were encountered: