Skip to content

Commit

Permalink
Showing 3 changed files with 30 additions and 1 deletion.
20 changes: 20 additions & 0 deletions spec/compiler/type_inference/splat_spec.cr
Original file line number Diff line number Diff line change
@@ -437,6 +437,26 @@ describe "Type inference: splat" do
)) { int32 }
end

it "accesses T when empty, via module" do
assert_type(%(
module Moo(T)
def t
T
end
end
struct Tuple
include Moo(Union(*T))
def self.new(*args)
args
end
end
Tuple.new.t
)) { no_return.metaclass }
end

describe Splat do
it "without splat" do
a_def = Def.new("foo", args: [Arg.new("x"), Arg.new("y")])
9 changes: 9 additions & 0 deletions spec/compiler/type_inference/union_spec.cr
Original file line number Diff line number Diff line change
@@ -140,4 +140,13 @@ describe "Type inference: union" do
Union(Int32, String).foo
)) { int32 }
end

it "merges types in the same hierarchy with Union" do
assert_type(%(
class Foo; end
class Bar < Foo; end
Union(Foo, Bar)
)) { types["Foo"].virtual_type!.metaclass }
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -2656,7 +2656,7 @@ module Crystal
end
type_var
end
program.type_merge_union_of(types).not_nil!
program.type_merge(types) || program.no_return
end

def new_generic_instance(program, generic_type, type_vars)

0 comments on commit 3d20332

Please sign in to comment.