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: 26a4c9777122
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: 32d7a51fe9d8
Choose a head ref
  • 3 commits
  • 4 files changed
  • 1 contributor

Commits on Jan 20, 2017

  1. Compiler specs: correctly forward end line

    Ary Borenszweig committed Jan 20, 2017

    Unverified

    No user is associated with the committer email.
    Copy the full SHA
    d38694c View commit details
  2. Compiler: better pretty print for MetaVar

    Ary Borenszweig committed Jan 20, 2017
    Copy the full SHA
    3a2a7b0 View commit details
  3. Fixed #3919: Variable assigned inside ensure does not have effect out…

    …side begin/ensure
    Ary Borenszweig committed Jan 20, 2017
    Copy the full SHA
    32d7a51 View commit details
Showing with 36 additions and 2 deletions.
  1. +21 −0 spec/compiler/semantic/exception_spec.cr
  2. +2 −2 spec/spec_helper.cr
  3. +4 −0 src/compiler/crystal/semantic/ast.cr
  4. +9 −0 src/compiler/crystal/semantic/main_visitor.cr
21 changes: 21 additions & 0 deletions spec/compiler/semantic/exception_spec.cr
Original file line number Diff line number Diff line change
@@ -421,4 +421,25 @@ describe "Semantic: exception" do
),
"instance variable '@x' of Foo must be Int32, not Nil"
end

it "assigns var inside ensure (1) (#3919)" do
assert_type(%(
begin
ensure
a = 1
end
a
)) { int32 }
end

it "assigns var inside ensure (2) (#3919)" do
assert_type(%(
a = true
begin
ensure
a = 1
end
a
)) { int32 }
end
end
4 changes: 2 additions & 2 deletions spec/spec_helper.cr
Original file line number Diff line number Diff line change
@@ -215,8 +215,8 @@ def assert_after_cleanup(before, after)
result.node.to_s.strip.should eq(after.strip)
end

def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = __FILE__, metaline = __LINE__)
it "says syntax error on #{str.inspect}", metafile, metaline do
def assert_syntax_error(str, message = nil, line = nil, column = nil, metafile = __FILE__, metaline = __LINE__, metaendline = __END_LINE__)
it "says syntax error on #{str.inspect}", metafile, metaline, metaendline do
begin
parse str
fail "expected SyntaxException to be raised", metafile, metaline
4 changes: 4 additions & 0 deletions src/compiler/crystal/semantic/ast.cr
Original file line number Diff line number Diff line change
@@ -453,6 +453,10 @@ module Crystal
io << " (assigned-to)" if assigned_to?
io << " (object id: #{object_id})"
end

def pretty_print(pp)
pp.text inspect
end
end

alias MetaVars = Hash(String, MetaVar)
9 changes: 9 additions & 0 deletions src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -2548,9 +2548,18 @@ module Crystal
end
end

before_ensure_vars = @vars.dup

node_ensure.accept self

@vars = after_handler_vars

# Variables declared or overwritten inside the ensure block
# must remain after the exception handler
exception_handler_vars.each do |name, var|
before_var = before_ensure_vars[name]?
@vars[name] = var unless var.same?(before_var)
end
else
@vars = exception_handler_vars
end