Skip to content

Commit

Permalink
Compiler: ignore type filters when accepting cast obj and to (#12668)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and beta-ziliani committed Nov 3, 2022
1 parent 3998670 commit d76cdee
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spec/compiler/semantic/nilable_cast_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,16 @@ describe "Semantic: nilable cast" do
base.as?(Moo)
)) { union_of([types["Foo"], types["Bar"], nil_type] of Type) }
end

it "doesn't introduce type filter for nilable cast object (#12661)" do
assert_type(%(
val = 1 || false
if val.as?(Char)
true
else
val
end
)) { union_of(int32, bool) }
end
end
8 changes: 6 additions & 2 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1766,10 +1766,14 @@ module Crystal
typed_def.raises = true
end

node.obj.accept self
ignoring_type_filters do
node.obj.accept self
end

@in_type_args += 1
node.to.accept self
ignoring_type_filters do
node.to.accept self
end
@in_type_args -= 1

node.obj.add_observer node
Expand Down

0 comments on commit d76cdee

Please sign in to comment.