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

macro 'method_missing' expects 1 argument (call) #7104

Open
vladfaust opened this issue Nov 22, 2018 · 5 comments
Open

macro 'method_missing' expects 1 argument (call) #7104

vladfaust opened this issue Nov 22, 2018 · 5 comments

Comments

@vladfaust
Copy link
Contributor

vladfaust commented Nov 22, 2018

I'd like this code to work (https://carc.in/#/r/5lun):

class Foo
  macro method_missing(call, file = __FILE__, line = __LINE__)
    {% raise "Method #{call.name} missing at #{file}:#{line}" %}
  end
end

Foo.new.bar

# Expected: Method bar missing at temp.cr:7
# Got: Error in line 2: macro 'method_missing' expects 1 argument (call)

To display the place from there the call occurred.

It would be even better if I could display the caller line in that macro (i.e. line: Foo.bar)

@jhass
Copy link
Member

jhass commented Nov 22, 2018

Maybe fixing

class Foo
  macro method_missing(call)
    {% raise "Method #{call.name} missing at #{call.filename}:#{call.line_number}" %}
  end
end

Foo.new.bar

would be good enough

@Sija
Copy link
Contributor

Sija commented Nov 22, 2018

@jhass nope, it returns Error in line 3: Method bar missing at nil:nil,
see https://carc.in/#/r/5lqt

@vladfaust there's a mistake in the code you've posted, Foo.bar should be Foo.new.bar

@jhass
Copy link
Member

jhass commented Nov 22, 2018

That's my point, maybe fixing the nils instead of making the macros signature more complex is good enough.

@vladfaust
Copy link
Contributor Author

@Sija, fixed, thanks.

Also call.receiver returns Nop.

Is it possible to somehow print the call line? E.g.

some_complex_call(Foo.new.bar)
                          ^~~~

@bew
Copy link
Contributor

bew commented Nov 24, 2018

@vladfaust that would be a job for call.raise "..." but the lack of location on the call makes it show nothing.

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

No branches or pull requests

4 participants