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

Wrong resolution of macros #3993

Closed
Sija opened this issue Feb 3, 2017 · 1 comment
Closed

Wrong resolution of macros #3993

Sija opened this issue Feb 3, 2017 · 1 comment

Comments

@Sija
Copy link
Contributor

Sija commented Feb 3, 2017

class Foo
  @buffer = [] of String

  def record(line : String)
    @buffer.shift?
    @buffer << line
  end

  def record(line : String? = nil)
    line ||= ""
    yield line
    # works when using `self.record`
    record line
  end
end

Foo.new.record { }

Above example fails with:

Error in line 17: instantiating 'Foo#record()'

in line 13: macro didn't expand to a valid program, it expanded to:

================================================================================
--------------------------------------------------------------------------------
   1.   struct line
   2.     
   3. 
   4.     def initialize()
   5.     end
   6. 
   7.     
   8. 
   9.     def clone
  10.       line.new()
  11.     end
  12.   end
--------------------------------------------------------------------------------
Syntax error in expanded macro: record:1: can't define struct inside def

  struct line
  ^

================================================================================

Problem is that record call is resolved to macro record instead of #record instance method.

@asterite
Copy link
Member

asterite commented Feb 7, 2017

Duplicate of #236

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants