Skip to content

Commit

Permalink
Merge pull request #38 from myst-lang/37_type_lookup_from_instances
Browse files Browse the repository at this point in the history
Fixes #37. Lookup Constants in both static and instance scopes.
  • Loading branch information
faultyserver authored Nov 11, 2017
2 parents bd7faff + 138c812 commit 63a3135
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
18 changes: 18 additions & 0 deletions spec/interpreter/nodes/instantiation_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -178,4 +178,22 @@ describe "Interpreter - Instantiation" do
result = itr.stack.pop
result.should eq(val(["hello", :nil]))
end

it "can find sibling types from instance scopes (GitHub issue #37)" do
itr = interpret_with_mocked_output %q(
deftype Foo
deftype Bar
end
def foo
%Bar{}
end
end
instance = %Foo{}.foo
)

itr.errput.to_s.should eq("")
itr.__typeof(itr.current_scope["instance"]).name.should eq("Bar")
end
end
7 changes: 6 additions & 1 deletion src/myst/interpreter/nodes/references.cr
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,12 @@ module Myst
end

def visit(node : Const)
stack.push(lookup(node))
if value = current_scope[node.name]? || __typeof(current_self).scope[node.name]
stack.push(value)
else
@callstack.push(node)
raise_not_found(node.name, current_self)
end
end

def visit(node : Underscore)
Expand Down

0 comments on commit 63a3135

Please sign in to comment.