Skip to content

Commit 2524362

Browse files
asteritejhass
authored andcommittedJan 4, 2018
Compiler: devirtualize inherited types
1 parent 7cdf9e3 commit 2524362

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed
 

Diff for: ‎spec/compiler/semantic/class_spec.cr

+14
Original file line numberDiff line numberDiff line change
@@ -1061,4 +1061,18 @@ describe "Semantic: class" do
10611061
),
10621062
"undefined method 'bar' for Foo:Class"
10631063
end
1064+
1065+
it "inherits self twice (#5495)" do
1066+
assert_type(%(
1067+
class Foo
1068+
class Bar < self
1069+
end
1070+
1071+
class Baz < self
1072+
end
1073+
end
1074+
1075+
{ {{ Foo::Bar.superclass }}, {{ Foo::Baz.superclass }} }
1076+
)) { tuple_of [types["Foo"].metaclass, types["Foo"].metaclass] }
1077+
end
10641078
end

Diff for: ‎src/compiler/crystal/semantic/top_level_visitor.cr

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
137137
# type parameters because they will always be unbound.
138138
superclass = lookup_type(node_superclass,
139139
free_vars: free_vars,
140-
find_root_generic_type_parameters: false)
140+
find_root_generic_type_parameters: false).devirtualize
141141
case superclass
142142
when GenericClassType
143143
node_superclass.raise "wrong number of type vars for #{superclass} (given 0, expected #{superclass.type_vars.size})"

0 commit comments

Comments
 (0)
Please sign in to comment.