Skip to content
Draft
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
9 changes: 9 additions & 0 deletions spec/compiler/semantic/def_overload_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1356,6 +1356,15 @@ describe "Semantic: def overload" do
CRYSTAL
end

it "says `no overload matches` instead of `use a more specific type` on union restriction that cannot be stored" do
assert_error <<-CRYSTAL, "expected argument #1 to 'foo' to be Array | String, not Int32"
def foo(x : Array | String)
end

foo(1)
CRYSTAL
end

it "finds method after including module in generic module (#1201)" do
assert_type(<<-CRYSTAL) { char }
module Bar
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/crystal/semantic/type_lookup.cr
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,10 @@ class Crystal::Type
return if !@raise && !type
type = type.not_nil!

check_type_can_be_stored(ident, type, "can't use #{type} in unions")
unless type.can_be_stored?
ident.raise "can't use #{type} in unions yet, use a more specific type" if @raise
return
end

type.virtual_type
end
Expand Down
Loading