Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: ignore type filters when accepting cast obj and to #12668

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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