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: 53be65dee36a
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: 08b568f363f8
Choose a head ref
  • 4 commits
  • 6 files changed
  • 1 contributor

Commits on Nov 18, 2016

  1. Copy the full SHA
    ca275a4 View commit details
  2. Copy the full SHA
    3170854 View commit details
  3. Spec: minor enhancements

    - Justify failed spec number
    - Shorter relative filename
    Ary Borenszweig committed Nov 18, 2016
    Copy the full SHA
    d705c41 View commit details
  4. Compiler: shorter relative filenames

    Ary Borenszweig committed Nov 18, 2016
    Copy the full SHA
    08b568f View commit details
Showing with 30 additions and 6 deletions.
  1. +11 −0 spec/compiler/codegen/is_a_spec.cr
  2. +11 −1 src/compiler/crystal/semantic/restrictions.cr
  3. +1 −0 src/compiler/crystal/types.cr
  4. +3 −3 src/compiler/crystal/util.cr
  5. +2 −1 src/spec/context.cr
  6. +2 −1 src/spec/source.cr
11 changes: 11 additions & 0 deletions spec/compiler/codegen/is_a_spec.cr
Original file line number Diff line number Diff line change
@@ -686,4 +686,15 @@ describe "Codegen: is_a?" do
Bar(Int32).new.as(Foo(Int32)).is_a?(Bar) ? 2 : 3
)).to_i.should eq(2)
end

it "doesn't consider generic type to be a generic type of a recursive alias (#3524)" do
run(%(
class Gen(T)
end
alias Type = Int32 | Gen(Type)
a = Gen(Int32).new
a.is_a?(Type)
)).to_b.should be_false
end
end
12 changes: 11 additions & 1 deletion src/compiler/crystal/semantic/restrictions.cr
Original file line number Diff line number Diff line change
@@ -328,7 +328,7 @@ module Crystal
end

def restrict(other : UnionType, context)
restricted = other.union_types.any? { |union_type| restriction_of?(union_type, context.instantiated_type) }
restricted = other.union_types.any? { |union_type| restrict(union_type, context) }
restricted ? self : nil
end

@@ -863,6 +863,16 @@ module Crystal
remove_alias.restrict(other, context)
end

def restrict(other : AliasType, context)
return self if self == other

if !self.simple? && !other.simple?
return nil
end

remove_alias.restrict(other, context)
end

def restrict(other, context)
return self if self == other

1 change: 1 addition & 0 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -2225,6 +2225,7 @@ module Crystal
class AliasType < NamedType
getter? value_processed = false
property! aliased_type : Type
getter? simple

def initialize(program, namespace, name, @value : ASTNode)
super(program, namespace, name)
6 changes: 3 additions & 3 deletions src/compiler/crystal/util.cr
Original file line number Diff line number Diff line change
@@ -3,10 +3,10 @@ module Crystal
dir = Dir.current
if filename.starts_with?(dir)
filename = filename[dir.size..-1]
if filename.starts_with? "/"
".#{filename}"
if filename.starts_with? '/'
filename[1..-1]
else
"./#{filename}"
filename
end
else
filename
3 changes: 2 additions & 1 deletion src/spec/context.cr
Original file line number Diff line number Diff line change
@@ -72,7 +72,8 @@ module Spec
failures_and_errors.each_with_index do |fail, i|
if ex = fail.exception
puts
puts " #{i + 1}) #{fail.description}"
puts "#{(i + 1).to_s.rjust(3, ' ')}) #{fail.description}"

if ex.is_a?(AssertionFailed)
source_line = Spec.read_line(ex.file, ex.line)
if source_line
3 changes: 2 additions & 1 deletion src/spec/source.cr
Original file line number Diff line number Diff line change
@@ -16,7 +16,8 @@ module Spec
def self.relative_file(file)
cwd = Dir.current
if file.starts_with?(cwd)
file = ".#{file[cwd.size..-1]}"
file = file[cwd.size..-1]
file = file[1..-1] if file.starts_with?('/')
end
file
end