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

Reset location after block yielding in macro expansion #3751

Merged
merged 3 commits into from
Dec 23, 2016

Commits on Dec 22, 2016

  1. Reset location after block yielding in macro expansion

    Introduce #<loc:save> and #<loc:reset> new pragma comment, #<loc:save>
    saves current location and #<loc:reset> resets it. They are useful to
    keep original location when block yielding in macro expansion.
    
    For example, this code makes broken error message:
    
        macro foo
          a = {{ yield }}
          a.ok
        end
    
        foo { 1 }
    
    It cannot be compiled and error message is:
    
        in foo.cr:7: undefined method 'ok' for Int32
    
    Error message points line 7 of foo.cr, but this code consists only 6 lines.
    
    This bug comes from a location is not reset after block yielding in
    macro expansion. For instance, `foo { 1 }` expands to:
    
        a =  begin #<loc:"foo.cr",6,7>1 end
        a.ok
    
    So, the parser reports `a.ok` is on line 7 of foo.cr.
    
    This commit fixes it by wrapping #<loc:save> and #<loc:reeset> to
    yielding expanded code, such a like:
    
        a =  #<loc:save>begin #<loc:"foo.cr",6,7>1 end#<loc:reset>
        a.ok
    makenowjust committed Dec 22, 2016
    Configuration menu
    Copy the full SHA
    ff4bfce View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    6b9d89c View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    837a0b0 View commit details
    Browse the repository at this point in the history