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

Fixes #37. Lookup Constants in both static and instance scopes. #38

Merged
merged 1 commit into from
Nov 11, 2017

Conversation

faultyserver
Copy link
Member

References to Constants can be done from both static and instance scopes. Until now, the lookup was always naively being performed on the current_scope, which could be either static or instance, but both would not be checked.

This led to the bug described in #37, where the current_scope was the scope of an instance, while the constant was defined on the static scope of current_self. In this case, the constant should have been resolved, but wasn't because only the instance scope was being checked.

An example of this behavior is

deftype Foo
  deftype Bar
  end

  def make_bar
    %Bar{}
  end
end

# `instance` should become an instance of `Foo.Bar`.
instance  = %Foo{}.make_bar

An interesting observation is that if Bar was defined outside of Foo, this bug would not occur, because both static and instance scopes have their parent set to the lexical scope they are defined in, and in that case Bar would have been defined in that lexical scope. In this case, however, Bar is defined on the static scope of Foo.

This behavior of lexical scoping might change in the future, where instance scopes won't see their lexical scope, but shouldn't cause issues beyond this.

References to Constants can be done from both static and instance scopes. Until now, the lookup was always naively being performed on the `current_scope`, which could be either static or instance, but both would not be checked.

This led to the bug described in #37, where the `current_scope` was the scope of an instance, while the constant was defined on the static scope of `current_self`. In this case, the constant should have been resolved, but wasn't because only the instance scope was being checked.
@faultyserver faultyserver added this to the Next milestone Nov 11, 2017
@faultyserver faultyserver merged commit 63a3135 into master Nov 11, 2017
@faultyserver faultyserver deleted the 37_type_lookup_from_instances branch November 11, 2017 02:14
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

Successfully merging this pull request may close these issues.

1 participant