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: acd6a7685ed4
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: 9897488181f0
Choose a head ref
  • 3 commits
  • 5 files changed
  • 1 contributor

Commits on Jul 5, 2016

  1. Fixed #2955: require relative doesn't work inside macros

    Ary Borenszweig committed Jul 5, 2016
    Copy the full SHA
    1e9625a View commit details
  2. Fixed #2954: use percent variables in Slice#[]

    Ary Borenszweig committed Jul 5, 2016
    2
    Copy the full SHA
    5dc17bc View commit details
  3. Fixed #2953: Compile error accessing an instance variable that was in…

    …itialized
    Ary Borenszweig committed Jul 5, 2016
    Copy the full SHA
    9897488 View commit details
Showing with 49 additions and 5 deletions.
  1. +33 −0 spec/compiler/type_inference/instance_var_spec.cr
  2. +10 −0 spec/std/slice_spec.cr
  3. +1 −1 src/compiler/crystal/semantic/base_type_visitor.cr
  4. +2 −1 src/compiler/crystal/types.cr
  5. +3 −3 src/slice.cr
33 changes: 33 additions & 0 deletions spec/compiler/type_inference/instance_var_spec.cr
Original file line number Diff line number Diff line change
@@ -3072,6 +3072,39 @@ describe "Type inference: instance var" do
"can't use Int as the type of an instance variable yet, use a more specific type"
end

it "shouldn't error when accessing instance var in initialized that's always initialized (#2953)" do
assert_type(%(
class Foo
@baz = Baz.new
def baz
@baz
end
end
class Bar < Foo
def initialize
@baz.x = 2
end
end
class Baz
def initialize
@x = 1
end
def x=(@x)
end
def x
@x
end
end
Bar.new.baz.x
)) { int32 }
end

# -----------------
# ||| OLD SPECS |||
# vvv vvv
10 changes: 10 additions & 0 deletions spec/std/slice_spec.cr
Original file line number Diff line number Diff line change
@@ -185,4 +185,14 @@ describe "Slice" do
slice[1].should eq('a')
slice[2].should eq("foo")
end

it "uses percent vars in [] macro (#2954)" do
slices = itself(Slice[1, 2], Slice[3])
slices[0].to_a.should eq([1, 2])
slices[1].to_a.should eq([3])
end
end

private def itself(*args)
args
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/base_type_visitor.cr
Original file line number Diff line number Diff line change
@@ -857,7 +857,7 @@ module Crystal
end

location = node.location
filenames = @mod.find_in_path(node.string, location.try &.filename)
filenames = @mod.find_in_path(node.string, location.try &.original_filename)
if filenames
nodes = Array(ASTNode).new(filenames.size)
filenames.each do |filename|
3 changes: 2 additions & 1 deletion src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -894,7 +894,8 @@ module Crystal
end

def has_instance_var_initializer?(name)
@instance_vars_initializers.try(&.any? { |init| init.name == name })
@instance_vars_initializers.try(&.any? { |init| init.name == name }) ||
ancestors.any?(&.has_instance_var_initializer?(name))
end
end

6 changes: 3 additions & 3 deletions src/slice.cr
Original file line number Diff line number Diff line change
@@ -23,11 +23,11 @@ struct Slice(T)
#
# See also: `Number.slice`.
macro [](*args)
slice = Slice(typeof({{*args}})).new({{args.size}})
%slice = Slice(typeof({{*args}})).new({{args.size}})
{% for arg, i in args %}
slice.to_unsafe[{{i}}] = {{arg}}
%slice.to_unsafe[{{i}}] = {{arg}}
{% end %}
slice
%slice
end

# Returns the size of this slice.