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

Commits on Feb 19, 2017

  1. Fixed some typos

    Ary Borenszweig committed Feb 19, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    bagder Daniel Stenberg
    Copy the full SHA
    18f079e View commit details
  2. Compiler: fixed ICE related to unknown ivars. Fixes #4050

    Ary Borenszweig committed Feb 19, 2017

    Verified

    This commit was signed with the committer’s verified signature.
    bagder Daniel Stenberg
    Copy the full SHA
    d94bb7e View commit details
Showing with 30 additions and 6 deletions.
  1. +24 −0 spec/compiler/semantic/instance_var_spec.cr
  2. +1 −1 src/compiler/crystal/semantic/main_visitor.cr
  3. +5 −5 src/string.cr
24 changes: 24 additions & 0 deletions spec/compiler/semantic/instance_var_spec.cr
Original file line number Diff line number Diff line change
@@ -4601,4 +4601,28 @@ describe "Semantic: instance var" do
Qux.new
)) { types["Qux"] }
end

it "errors if unknown ivar through macro (#4050)" do
assert_error %(
class Foo
def initialize(**attributes)
{% for var in @type.instance_vars %}
if arg = attributes[:{{var.name.id}}]?
@{{var.name.id}} = arg
end
{% end %}
end
end
class Bar < Foo
def initialize(**attributes)
@bar = true
super
end
end
Bar.new
),
"Can't infer the type of instance variable '@bar' of Foo"
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/main_visitor.cr
Original file line number Diff line number Diff line change
@@ -3009,7 +3009,7 @@ module Crystal
@vars.each do |name, var|
if name.starts_with? '@'
if var.nil_if_read?
ivar = owner.lookup_instance_var(name)
ivar = lookup_instance_var(var, owner)
ivar.bind_to program.nil_var
end

10 changes: 5 additions & 5 deletions src/string.cr
Original file line number Diff line number Diff line change
@@ -98,15 +98,15 @@ require "c/string"
# byte sequence according to UTF-8. This can happen if the string is created
# via one of the constructors that accept bytes, or when getting a string
# from `String.build` or `IO::Memory`. No exception will be raised, but
# invalid byte sequences, when asked as chars, will use the unicode replamcenet
# invalid byte sequences, when asked as chars, will use the unicode replacement
# char (value 0xFFFD). For example:
#
# ```
# # here 255 is not a valid byte value in the UTF-8 encoding
# string = String.new(Bytes[255, 97])
# string.valid_encoding? # => false
#
# # The first char here is the unicode replacemnt char
# # The first char here is the unicode replacement char
# string.chars # => ['�', 'a']
# ```
#
@@ -1209,9 +1209,9 @@ class String
# Returns `nil` if this string does not denote an hexstring.
#
# ```
# "0102031aff".hexbytes? # => Bytes[1, 2, 3, 26, 255]
# "1".hexbytes? # => nil
# "hello world".hexbytes # => nil
# "0102031aff".hexbytes? # => Bytes[1, 2, 3, 26, 255]
# "1".hexbytes? # => nil
# "hello world".hexbytes? # => nil
# ```
def hexbytes? : Bytes?
return unless bytesize.divisible_by?(2)