Skip to content

Commit

Permalink
Compiler: devirtualize inherited types
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and jhass committed Jan 4, 2018
1 parent 7cdf9e3 commit 2524362
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
14 changes: 14 additions & 0 deletions spec/compiler/semantic/class_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1061,4 +1061,18 @@ describe "Semantic: class" do
),
"undefined method 'bar' for Foo:Class"
end

it "inherits self twice (#5495)" do
assert_type(%(
class Foo
class Bar < self
end
class Baz < self
end
end
{ {{ Foo::Bar.superclass }}, {{ Foo::Baz.superclass }} }
)) { tuple_of [types["Foo"].metaclass, types["Foo"].metaclass] }
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/top_level_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
# type parameters because they will always be unbound.
superclass = lookup_type(node_superclass,
free_vars: free_vars,
find_root_generic_type_parameters: false)
find_root_generic_type_parameters: false).devirtualize
case superclass
when GenericClassType
node_superclass.raise "wrong number of type vars for #{superclass} (given 0, expected #{superclass.type_vars.size})"
Expand Down

0 comments on commit 2524362

Please sign in to comment.