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: c2cabffcf35b
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: 34689cbcba1d
Choose a head ref
  • 2 commits
  • 3 files changed
  • 1 contributor

Commits on Sep 28, 2016

  1. Fixed #3360: incorrect type flow regarding unreachable and '&&'

    Ary Borenszweig committed Sep 28, 2016
    Copy the full SHA
    c79f583 View commit details
  2. MD5: some renames

    Ary Borenszweig committed Sep 28, 2016
    Copy the full SHA
    34689cb View commit details
Showing with 20 additions and 8 deletions.
  1. +12 −0 spec/compiler/semantic/if_spec.cr
  2. +2 −2 src/compiler/crystal/semantic/main_visitor.cr
  3. +6 −6 src/crypto/md5.cr
12 changes: 12 additions & 0 deletions spec/compiler/semantic/if_spec.cr
Original file line number Diff line number Diff line change
@@ -227,4 +227,16 @@ describe "Semantic: if" do
foo(x)
)) { int32 }
end

it "types variable after unreachable else of && (#3360)" do
assert_type(%(
def test
foo = 1 if 1
return 1 unless foo && foo
foo
end
test
), inject_primitives: false) { int32 }
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -1766,15 +1766,15 @@ module Crystal
next if then_var.same?(else_var)

if_var = MetaVar.new(name)
if_var.nil_if_read = !!(then_var.try(&.nil_if_read?) || else_var.try(&.nil_if_read?))

# Check if no types were changes in either then 'then' and 'else' branches
if cond_var && then_var.same?(before_then_var) && else_var.same?(before_else_var) && !then_unreachable && !else_unreachable
cond_var.nil_if_read = if_var.nil_if_read?
@vars[name] = cond_var
next
end

if_var.nil_if_read = !!(then_var.try(&.nil_if_read?) || else_var.try(&.nil_if_read?))

if then_var && else_var
if then_unreachable
if_var.bind_to conditional_no_return(node.then, then_var)
12 changes: 6 additions & 6 deletions src/crypto/md5.cr
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ class Crypto::MD5
#
# Crypto::MD5.hex_digest("foo") # => "acbd18db4cc2f85cedef654fccc4a4d8"
def self.hex_digest(data : String | Slice(UInt8)) : String
context = Context.new
context = ContextImpl.new
context.update data
context.final
context.hex
@@ -18,22 +18,22 @@ class Crypto::MD5
# ctx.update "oo"
# end # => "acbd18db4cc2f85cedef654fccc4a4d8"
def self.hex_digest : String
context = ContextWrapper.new
context = Context.new
yield context
context.final
context.hex
end

private class ContextWrapper
getter context : Context
class Context
getter context : ContextImpl
delegate update, final, hex, to: context

def initialize
@context = Context.new
@context = ContextImpl.new
end
end

private struct Context
private struct ContextImpl
def initialize
@i = StaticArray(UInt32, 2).new(0_u32)
@buf = StaticArray(UInt32, 4).new(0_u32)