Skip to content

Commit

Permalink
Compiler: fixed incorrect metaclass type id. Fixes #3490
Browse files Browse the repository at this point in the history
Ary Borenszweig committed Oct 31, 2016

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
1 parent 7e1afdb commit 13733dc
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 31 additions & 0 deletions spec/compiler/codegen/cast_spec.cr
Original file line number Diff line number Diff line change
@@ -358,4 +358,35 @@ describe "Code gen: cast" do
(v || {v}).as(Bool | Float64)
))
end

it "codegens class method when type id is available but not a virtual type (#3490)" do
run(%(
class Class
def name : String
{{ @type.name.stringify }}
end
end
class Super
end
module Mixin
end
class A < Super
include Mixin
end
class B < Super
include Mixin
end
a = A.new.as(Super)
if a.is_a?(Mixin)
a.class.name
else
"Nope"
end
)).to_string.should eq("A")
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/primitives.cr
Original file line number Diff line number Diff line change
@@ -613,7 +613,7 @@ class Crystal::CodeGenVisitor
end

def codegen_primitive_class_with_type(type : Type, value)
type_id(type)
type_id(type.metaclass)
end

def codegen_primitive_proc_call(node, target_def, call_args)

0 comments on commit 13733dc

Please sign in to comment.