-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error: ignored invalid for loop for it
triggered when changing a #
to a ##
#9230
Comments
In your case1, if you start the doc comment on the template line the error goes away (i don't know why). when defined(case1):
template items*[A,B](t: Table[A,B]): tuple[key: A, val: B] = ##
## iterates over (key, value) tuples in the table `t`.
##
## Example:
##
## .. code-block:: nim
## import sequtils
## let a = {10: "foo", 12: "bar"}.toTable
## doAssert mapIt(a, it.key) == [10, 12]
## doAssert mapIt(a, it.val)[1] == "bar"
##
pairs(t) You should come up with a better use case than this bizarre way of writing |
Please, please stop writing these |
The reason of the bug is that the test here considers that iterator is not used in a Another example of such bug where using a template is required by the context: type
Melon = object
template pairs*(m: Melon): tuple[key: int, val: int] =
let iter = iterator(melon: Melon): tuple[key: int, val: int] =
for i in a .. 10:
yield (key: i, val: i * i)
iter(m)
block:
let a = 2
let m = Melon()
for k, v in m:
echo "k=", k, "; v=", v |
this crops up in many places, eg #14420 (comment) when true: # D20200525T015650
type Foo = object
x: float
proc fn(a: var Foo): var float =
## discard <- turn this into a comment (or a `discard`) and error disappears
# result = a.x # this would work
a.x # Error: limited VM support for 'addr'
template main =
var a = Foo()
discard fn(a)
main() # works
static: main() # fails |
this prevents the simpler suggestion in #9217 (comment)
The text was updated successfully, but these errors were encountered: