Skip to content
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

fieldPairs bug has ugly error message #7533

Open
timotheecour opened this issue Apr 6, 2018 · 4 comments

Comments

Projects
None yet
7 participants
@timotheecour
Copy link
Contributor

commented Apr 6, 2018

import typetraits
type
  Myobj=object
    x1:int

var x:Myobj

# the two symbols with the identifier ``name`` will clash.
for name, value in x.fieldPairs:
  # BUG: ???(???, 0) Error: in expression 'type(x.x1)."x1"': identifier expected, but found '"x1"'
  echo value.type.name
  • should not be an error
  • error should at least not contain ???

workaround

import typetraits
type
  Myobj=object
    x1:int

var x:Myobj

for fieldname, value in x.fieldPairs:
  echo value.type.name
@mjendrusch

This comment has been minimized.

Copy link
Contributor

commented Apr 7, 2018

This seems to be a known bug of fieldPairs, as written in the system docs:

Warning: This really transforms the 'for' and unrolls the loop. The current implementation also has a bug that affects symbol binding in the loop body.

It looks like the expansion of fieldPairs is not hygienic and thus every occurrence of name in the loop body is replaced by the string of a field name, leading to that error.
A more palatable workaround would be to do something like:

import typetraits

type
  MyObj = object
    x1: int

var x: MyObj

# Use nn to not clash with
# typetraits.name:
for nn, value in x.fieldPairs:
  echo value.type.name
  echo value
  echo nn

@dom96 dom96 added the Error messages label Apr 7, 2018

@zah zah self-assigned this Apr 11, 2018

@narimiran

This comment has been minimized.

Copy link
Member

commented Feb 26, 2019

Since this bug is documented (i.e. this issue is not needed to bring our attention to it), and the workaround is basically to use anything else besides name, I'm closing this.

@narimiran narimiran closed this Feb 26, 2019

@Clyybber

This comment has been minimized.

Copy link
Contributor

commented Feb 26, 2019

It's good to have an issue that tracks this bug, even if it is documented IMO.

@Araq

This comment has been minimized.

Copy link
Member

commented Feb 26, 2019

Plus the line info is really bad.

@Araq Araq reopened this Feb 26, 2019

@krux02 krux02 changed the title fieldPairs + value.type gives: ???(???, 0) Error: in expression 'type(x.x1)."x1"': identifier expected, but found '"x1"' fieldPairs bug has ugly error message Feb 26, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.