Skip to content

Commit

Permalink
Compiler: lookup for abstract def implementation in all ancestors. Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Mar 3, 2017
1 parent e1cdde8 commit 812223f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
19 changes: 19 additions & 0 deletions spec/compiler/semantic/abstract_def_spec.cr
Expand Up @@ -375,4 +375,23 @@ describe "Semantic: abstract def" do
end
)
end

it "finds implements in included module in disorder (#4052)" do
semantic %(
module B
abstract def x
end
module C
def x
:x
end
end
class A
include C
include B
end
)
end
end
11 changes: 4 additions & 7 deletions src/compiler/crystal/semantic/abstract_def_checker.cr
Expand Up @@ -74,7 +74,7 @@ class Crystal::AbstractDefChecker
end

subtypes.try &.each do |subtype|
next if implements_with_parents?(subtype, method, base)
next if implements_with_ancestors?(subtype, method, base)

# Union doesn't need a hash, dup, to_s, etc., methods because it's special
next if subtype == @program.union
Expand All @@ -87,15 +87,12 @@ class Crystal::AbstractDefChecker
end
end

def implements_with_parents?(type : Type, method : Def, base)
def implements_with_ancestors?(type : Type, method : Def, base)
return true if implements?(type, method, base)

type.parents.try &.each do |parent|
break if parent == base
return true if implements?(parent, method, base)
type.ancestors.any? do |ancestor|
implements?(ancestor, method, base)
end

return false
end

def implements?(type : Type, method : Def, base)
Expand Down

1 comment on commit 812223f

@luislavena
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! ❤️ ❤️ 😻

Please sign in to comment.