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

Semantic: fix to look up type var in macro called inside class #5349

Conversation

makenowjust
Copy link
Contributor

Fixed #5343

@free_vars_cache = {} of GenericInstanceType => Hash(String, TypeVar)

private def macro_free_vars_for_type(type)
unless free_vars = @free_vars_cache[type]?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use the following syntax?

@free_vars_cache[type] ||= begin
  # build the value for this *type* here
end

This will get the value associated with type, and if there is none, build the value and associate it with type in the hash, and return it.

@makenowjust makenowjust force-pushed the fix/crystal/lookup-type-var-in-macro-called-in-class branch from ab95e27 to 1e846c9 Compare December 5, 2017 15:24
@bew
Copy link
Contributor

bew commented Dec 5, 2017

Hmm now we have a (maybe?) unwanted behavior:

class Foo(T)
  macro foo(node)
    {{node.resolve}}
  end
end

alias FooInt32 = Foo(Int32)

class Bar
  def self.foo
    FooInt32.foo T
  end
end

p Bar.foo # => Int32

What I want to hightlight here is that in Bar when you have no idea that how that foo macro works, you can still 'access' something that you are not aware of ('not sure how to explain my point ><)

Maybe it's not an issue after all, but this is definitely not documented, and is unexpected for a Foo user' point of view I think.

@bew
Copy link
Contributor

bew commented Feb 23, 2018

I think this can be closed in favor of #5354.

@jkthorne
Copy link
Contributor

@makenowjust what is the status of this PR?

@bew
Copy link
Contributor

bew commented Aug 14, 2018

#5354 has been merged, we can close this pr now

@makenowjust
Copy link
Contributor Author

@bew Yes. I'll close.

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

Successfully merging this pull request may close these issues.

None yet

4 participants