Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 51bf36933997
Choose a base ref
...
head repository: crystal-lang/crystal
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 181986dd410b
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 17, 2017

  1. Unverified

    This user has not yet uploaded their public signing key.
    Copy the full SHA
    e1aa6c0 View commit details
  2. Merge pull request #5135 from asterite/bug/5073-union-of-numbers

    Semantic: don't combine union of Number and Number subclass into Number
    asterite authored Oct 17, 2017
    Copy the full SHA
    181986d View commit details
Showing with 23 additions and 1 deletion.
  1. +22 −0 spec/compiler/semantic/instance_var_spec.cr
  2. +1 −1 src/compiler/crystal/semantic/type_merge.cr
22 changes: 22 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
@@ -4779,4 +4779,26 @@ describe "Semantic: instance var" do
A.new.a
)) { int32 }
end

it "doesn't combine union of Number and Number subclass (#5073)" do
assert_type(%(
class Gen(T)
end
struct A < Number
def hash(hasher)
hasher
end
def to_s(io : IO)
end
end
class Foo
@foo = Gen(Int32 | A).new
end
Foo.new.@foo
)) { generic_class "Gen", union_of(int32, types["A"]) }
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/type_merge.cr
Original file line number Diff line number Diff line change
@@ -325,7 +325,7 @@ private def class_common_ancestor(t1, t2)
end

case t1
when t1.program.struct, t1.program.int, t1.program.float
when t1.program.struct, t1.program.number, t1.program.int, t1.program.float
return nil
when t2
return t1