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

'undefined local variable or method' when using typeof() #2052

Closed
stugol opened this issue Jan 24, 2016 · 2 comments · Fixed by #5192
Closed

'undefined local variable or method' when using typeof() #2052

stugol opened this issue Jan 24, 2016 · 2 comments · Fixed by #5192
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler

Comments

@stugol
Copy link

stugol commented Jan 24, 2016

The following code works:

def _Type
    Int32
end
def test(&callback : typeof(_Type)->)
end
test do |a|
end

However, when the code is inside a class, we get an error. See https://play.crystal-lang.org/#/r/qdc

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Jan 24, 2016
@asterite
Copy link
Member

Yes, that should probably work

@ayazhafiz
Copy link
Contributor

Interestingly, this works if _Type is explicitly called from the object:

class TCPBase
  def _Type
    Int32
  end
  
  def test(&callback : typeof(self._Type) -> Nil)
  end
end
TCPBase.new.test { |a| } # compiles

My inclination is that this has to do with the scope of the arguments to typeof, though I can't deduce much from the source code and may be totally wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants