Skip to content

Commit

Permalink
Compiler: fixed VirtualMetaclassType#metaclass (#4375)
Browse files Browse the repository at this point in the history
Compiler: fixed VirtualMetaclassType#metaclass

Fixes #4374
  • Loading branch information
rockwyc992 authored and Martin Verzilli committed May 13, 2017
1 parent 08c6e8f commit c27629f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
12 changes: 12 additions & 0 deletions spec/compiler/codegen/is_a_spec.cr
Expand Up @@ -715,4 +715,16 @@ describe "Codegen: is_a?" do
1.to_s.is_a?(B)
)).to_b.should be_true
end

it "says true for Class.is_a?(Class.class) (#4374)" do
run("
Class.is_a?(Class.class)
").to_b.should be_true
end

it "says true for Class.is_a?(Class.class.class) (#4374)" do
run("
Class.is_a?(Class.class.class)
").to_b.should be_true
end
end
1 change: 0 additions & 1 deletion src/compiler/crystal/program.cr
Expand Up @@ -179,7 +179,6 @@ module Crystal
string.declare_instance_var("@c", uint8)

types["Class"] = klass = @class = MetaclassType.new(self, object, value, "Class")
klass.metaclass = klass
klass.allowed_in_generics = false

types["Struct"] = struct_t = @struct_t = NonGenericClassType.new self, self, "Struct", value
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/crystal/types.cr
Expand Up @@ -2900,6 +2900,10 @@ module Crystal
super(program)
end

def metaclass
program.class_type
end

def parents
@parents ||= [instance_type.superclass.try(&.metaclass) || program.class_type] of Type
end
Expand Down

0 comments on commit c27629f

Please sign in to comment.