Skip to content

Commit

Permalink
Compiler: use path lookup when looking up type for autocast match (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored Jan 28, 2021
1 parent 7684094 commit 8d7a8c9
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/compiler/semantic/automatic_cast_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -596,4 +596,24 @@ describe "Semantic: automatic cast" do
),
"ambiguous call, implicit cast of 255 matches all of UInt64, Int64"
end

it "autocasts nested type from non-nested type (#10315)" do
assert_no_errors(%(
module Moo
enum Color
Red
end
abstract class Foo
def initialize(color : Color = :red)
end
end
end
class Bar < Moo::Foo
end
Bar.new
))
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -769,7 +769,7 @@ module Crystal
# OK
else
# Check autocast too
restriction_type = scope.lookup_type(restriction, free_vars: free_vars)
restriction_type = (path_lookup || scope).lookup_type(restriction, free_vars: free_vars)
if casted_value = check_automatic_cast(value, restriction_type, node)
value = casted_value
else
Expand Down

0 comments on commit 8d7a8c9

Please sign in to comment.