Skip to content

Commit

Permalink
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
@@ -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
@@ -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})"

0 comments on commit 2524362

Please sign in to comment.