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

Experimental . operator confuses the dot call syntax notation #7777

Closed
PMunch opened this issue May 5, 2018 · 0 comments · Fixed by #20931
Closed

Experimental . operator confuses the dot call syntax notation #7777

PMunch opened this issue May 5, 2018 · 0 comments · Fixed by #20931

Comments

@PMunch
Copy link
Contributor

PMunch commented May 5, 2018

I've been struggling with a hard to track down bug in my protobuf library for quite a while now. I couldn't for the life of me figure out what the error message I got meant. The problem was a simple missing export marker on a template, but the error pointed to something completely different. The below example shows what I'm talking about:

{.experimental.}
import macros

type
  TestType = ref object
    private_field: string

# This is the analogue to my procedure that was missing an export marker
#template getField(obj, field: untyped): untyped =
#  obj.field

# This experimental will match all unmatched field access to this macro before failing.
macro `.`(obj: TestType, field: untyped): untyped =
  # This is probably not strictly necessary for this example, but it shows what I'm
  # trying to achieve with the `.` macro.
  let private = newIdentNode("private_" & $field)
  # This is where the problem lies. The first commented statement will create error 1,
  # while the second statement would create error 2 below.
  result = quote do:
    #getField(`obj`, `private`)
    #`obj`.getField(`private`)

var tt = new TestType
tt.private_field = "Hello world"

echo tt.field

Error 1 (this is what we would normally see):
Error: undeclared identifier: 'getField'
Error 2 (this is what confused me):
Error: undeclared identifier: 'private_field'
If we remove the comments on the getField proc both examples work

metagn added a commit to metagn/Nim that referenced this issue Nov 26, 2022
Araq pushed a commit that referenced this issue Nov 28, 2022
* better error messages for dot operators [backport]

fixes #13063

* also fixes #7777

* fix #6981 and #9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
narimiran pushed a commit that referenced this issue Nov 30, 2022
* better error messages for dot operators [backport]

fixes #13063

* also fixes #7777

* fix #6981 and #9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements

(cherry picked from commit 555c5ed)
survivorm pushed a commit to survivorm/Nim that referenced this issue Feb 28, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
capocasa pushed a commit to capocasa/Nim that referenced this issue Mar 31, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
bung87 pushed a commit to bung87/Nim that referenced this issue Jul 29, 2023
* better error messages for dot operators [backport]

fixes nim-lang#13063

* also fixes nim-lang#7777

* fix nim-lang#6981 and nim-lang#9831 too

* fix

* minor improvement

* sus test fixes

* make test multiplatform lol

* fix nimsuggest test, extra improvements
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants