From 78f62f17c3da99fee0bdb4b910319ea04f504a8c Mon Sep 17 00:00:00 2001 From: Ary Borenszweig <aborenszweig@manas.com.ar> Date: Sun, 25 Jan 2015 00:14:17 -0300 Subject: [PATCH] Fixed #348: Can't call ConditionVariable#inspect --- spec/compiler/codegen/class_spec.cr | 18 ++++++++++++++++++ src/compiler/crystal/codegen/codegen.cr | 2 +- .../crystal/semantic/type_inference.cr | 2 +- src/compiler/crystal/types.cr | 2 ++ 4 files changed, 22 insertions(+), 2 deletions(-) diff --git a/spec/compiler/codegen/class_spec.cr b/spec/compiler/codegen/class_spec.cr index 84c17d49c5..4b1edd9f74 100644 --- a/spec/compiler/codegen/class_spec.cr +++ b/spec/compiler/codegen/class_spec.cr @@ -542,4 +542,22 @@ describe "Code gen: class" do ex.foo )) end + + it "resolves type declaration when accessing instance var (#348)" do + build(%( + require "prelude" + + lib C + type Foo = Int64[8] + end + + class Bar + def initialize + @foo :: C::Foo + end + end + + Bar.new.inspect + )) + end end diff --git a/src/compiler/crystal/codegen/codegen.cr b/src/compiler/crystal/codegen/codegen.cr index cf0fe5875a..18081b3e85 100644 --- a/src/compiler/crystal/codegen/codegen.cr +++ b/src/compiler/crystal/codegen/codegen.cr @@ -330,7 +330,7 @@ module Crystal when Var context.vars[node_exp.name].pointer when InstanceVar - instance_var_ptr (context.type as InstanceVarContainer), node_exp.name, llvm_self_ptr + instance_var_ptr (context.type.remove_typedef as InstanceVarContainer), node_exp.name, llvm_self_ptr when Path accept(node_exp) global_name = node_exp.target_const.not_nil!.llvm_name diff --git a/src/compiler/crystal/semantic/type_inference.cr b/src/compiler/crystal/semantic/type_inference.cr index 0c41e825d6..4e79999a6d 100644 --- a/src/compiler/crystal/semantic/type_inference.cr +++ b/src/compiler/crystal/semantic/type_inference.cr @@ -279,7 +279,7 @@ module Crystal end def lookup_instance_var(node) - case scope = @scope + case scope = @scope.try &.remove_typedef when Nil node.raise "can't use instance variables at the top level" when Program diff --git a/src/compiler/crystal/types.cr b/src/compiler/crystal/types.cr index 83f642091c..f2bfcaa1dd 100644 --- a/src/compiler/crystal/types.cr +++ b/src/compiler/crystal/types.cr @@ -1797,6 +1797,8 @@ module Crystal delegate pointer?, typedef delegate defs, typedef delegate macros, typedef + delegate passed_by_value?, typedef + delegate reference_like?, typedef def parents typedef_parents = typedef.parents -- GitLab