Skip to content

Commit

Permalink
Compiler: fixed bug regarding generic type, module inclusion and inst…
Browse files Browse the repository at this point in the history
…ance vars. Fixes #3635
  • Loading branch information
asterite committed Dec 4, 2016
1 parent 4b7ef7d commit 324d5ba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
22 changes: 22 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Expand Up @@ -4538,4 +4538,26 @@ describe "Semantic: instance var" do
Foo.new
)) { types["Foo"] }
end

it "doesn't error if inheriting generic instance (#3635)" do
assert_type(%(
module Core(T)
@a : Bool
end
class Base(T)
include Core(Int32)
@a = true
end
class Foo < Base(String)
def a
@a
end
end
Foo.new.a
)) { bool }
end
end
8 changes: 8 additions & 0 deletions src/compiler/crystal/semantic/type_declaration_processor.cr
Expand Up @@ -236,6 +236,10 @@ struct Crystal::TypeDeclarationProcessor
end

private def process_owner_instance_var_declaration(owner, name, type_decl)
# Generic instances already have their instance vars
# set from uninstantiated generic types
return if owner.is_a?(GenericInstanceType)

# Check if a superclass already defined this variable
supervar = owner.lookup_instance_var?(name)

Expand Down Expand Up @@ -313,6 +317,10 @@ struct Crystal::TypeDeclarationProcessor
end

private def process_owner_guessed_instance_var_declaration(owner, name, type_info)
# Generic instances already have their instance vars
# set from uninstantiated generic types
return if owner.is_a?(GenericInstanceType)

case owner
when NonGenericClassType
# If a superclass already defines this variable we ignore
Expand Down

0 comments on commit 324d5ba

Please sign in to comment.