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: d3694c0ae627
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: bbf79fb04373
Choose a head ref
  • 3 commits
  • 6 files changed
  • 1 contributor

Commits on Jun 7, 2017

  1. Copy the full SHA
    644b59b View commit details
  2. Copy the full SHA
    cb1061b View commit details
  3. Copy the full SHA
    bbf79fb View commit details
2 changes: 2 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Original file line number Diff line number Diff line change
@@ -1031,4 +1031,6 @@ describe Crystal::Formatter do
assert_format "def foo(a, **b : Int32)\nend"

assert_format "foo\n \nbar", "foo\n\nbar"

assert_format "\"\" + <<-END\n bar\n END"
end
16 changes: 16 additions & 0 deletions spec/compiler/semantic/def_overload_spec.cr
Original file line number Diff line number Diff line change
@@ -944,4 +944,20 @@ describe "Semantic: def overload" do
),
"no overload matches"
end

it "overloads with named argument (#4465)" do
assert_type(%(
def do_something(value : Int32)
value + 1
1.5
end
def do_something(value : Char)
value.ord
false
end
do_something value: 7.as(Int32 | Char)
)) { union_of float64, bool }
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/macros/methods.cr
Original file line number Diff line number Diff line change
@@ -1490,11 +1490,11 @@ module Crystal
end

def self.subclasses(type)
ArrayLiteral.map(type.subclasses) { |subtype| TypeNode.new(subtype) }
ArrayLiteral.map(type.devirtualize.subclasses) { |subtype| TypeNode.new(subtype) }
end

def self.all_subclasses(type)
ArrayLiteral.map(type.all_subclasses) { |subtype| TypeNode.new(subtype) }
ArrayLiteral.map(type.devirtualize.all_subclasses) { |subtype| TypeNode.new(subtype) }
end

def self.union_types(type)
9 changes: 5 additions & 4 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
@@ -213,7 +213,7 @@ class Crystal::Call
end

@uses_with_scope = true
instantiate matches, owner, self_type: nil, named_args_types: named_args_types
instantiate matches, owner, self_type: nil
end

def lookup_matches_in_type(owner, arg_types, named_args_types, self_type, def_name, search_in_parents)
@@ -267,7 +267,7 @@ class Crystal::Call
attach_subclass_observer instance_type.base_type
end

instantiate matches, owner, self_type, named_args_types
instantiate matches, owner, self_type
end

def lookup_matches_checking_expansion(owner, signature, search_in_parents = true)
@@ -318,7 +318,7 @@ class Crystal::Call
end
end

def instantiate(matches, owner, self_type, named_args_types)
def instantiate(matches, owner, self_type)
block = @block

typed_defs = Array(Def).new(matches.size)
@@ -346,6 +346,7 @@ class Crystal::Call
end
match_owner = match.context.instantiated_type
def_instance_owner = (self_type || match_owner).as(DefInstanceContainer)
named_args_types = match.named_arg_types

def_instance_key = DefInstanceKey.new(match.def.object_id, lookup_arg_types, block_type, named_args_types)
typed_def = def_instance_owner.lookup_def_instance def_instance_key if use_cache
@@ -616,7 +617,7 @@ class Crystal::Call
parent_visitor.check_self_closured
end

typed_defs = instantiate matches, scope, self_type: nil, named_args_types: named_args_types
typed_defs = instantiate matches, scope, self_type: nil
typed_defs.each do |typed_def|
typed_def.next = parent_visitor.typed_def
end
3 changes: 2 additions & 1 deletion src/compiler/crystal/syntax/lexer.cr
Original file line number Diff line number Diff line change
@@ -11,7 +11,8 @@ module Crystal
property? slash_is_regex : Bool
getter reader : Char::Reader
getter token : Token
getter line_number : Int32
property line_number : Int32
property column_number : Int32
@filename : String | VirtualFile | Nil
@stacked_filename : String | VirtualFile | Nil
@token_end_location : Location?
8 changes: 6 additions & 2 deletions src/compiler/crystal/tools/formatter.cr
Original file line number Diff line number Diff line change
@@ -606,7 +606,7 @@ module Crystal
end

def space_slash_newline?
pos = @lexer.current_pos
pos, line, col = @lexer.current_pos, @lexer.line_number, @lexer.column_number
while true
char = @lexer.current_char
case char
@@ -620,11 +620,13 @@ module Crystal
end
end
@lexer.current_pos = pos
@lexer.line_number = line
@lexer.column_number = col
false
end

def space_newline?
pos = @lexer.current_pos
pos, line, col = @lexer.current_pos, @lexer.line_number, @lexer.column_number
while true
char = @lexer.current_char
case char
@@ -638,6 +640,8 @@ module Crystal
end
end
@lexer.current_pos = pos
@lexer.line_number = line
@lexer.column_number = col
false
end