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: da3c38ec83ff
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: 969c1031f00f
Choose a head ref
  • 3 commits
  • 8 files changed
  • 1 contributor

Commits on Jul 22, 2016

  1. Compiler: don't use init flag for simple constants

    Ary Borenszweig committed Jul 22, 2016

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
    Copy the full SHA
    e91a76c View commit details
  2. Fixed #3029: incorrect restriction for module vs. Path

    Ary Borenszweig committed Jul 22, 2016
    Copy the full SHA
    f6b9b0c View commit details
  3. Fixed #3032: Proc that returns NoReturn should be compatible with a p…

    …roc that returns any type
    Ary Borenszweig committed Jul 22, 2016
    Copy the full SHA
    969c103 View commit details
16 changes: 16 additions & 0 deletions spec/compiler/type_inference/module_spec.cr
Original file line number Diff line number Diff line change
@@ -966,4 +966,20 @@ describe "Type inference: module" do
),
"undefined constant X::Bar"
end

it "can restrict module with module (#3029)" do
assert_type(%(
module Foo
end
class Gen(T)
end
def foo(x : Gen(Foo))
1
end
foo(Gen(Foo).new)
)) { int32 }
end
end
22 changes: 22 additions & 0 deletions spec/compiler/type_inference/proc_spec.cr
Original file line number Diff line number Diff line change
@@ -899,4 +899,26 @@ describe "Type inference: proc" do
Foo.new.x
)) { proc_of([int32, char, string]) }
end

it "can assign NoReturn proc to other proc (#3032)" do
assert_type(%(
lib LibC
fun exit : NoReturn
end
class Foo
@x : -> Int32
def initialize
@x = ->{ LibC.exit }
end
def x
@x
end
end
Foo.new.x
)) { proc_of(int32) }
end
end
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
@@ -837,7 +837,7 @@ module Crystal
return false
when Path
const = target.target_const.not_nil!
if const.used && !const.simple?
if const.used? && !const.simple?
initialize_const(const)
end
@last = llvm_nil
2 changes: 2 additions & 0 deletions src/compiler/crystal/semantic/base_type_visitor.cr
Original file line number Diff line number Diff line change
@@ -46,6 +46,8 @@ module Crystal
type.vars = const_def.vars
type.visitor = self
type.used = true

program.class_var_and_const_initializers << type
end

node.target_const = type
2 changes: 1 addition & 1 deletion src/compiler/crystal/semantic/cleanup_transformer.cr
Original file line number Diff line number Diff line change
@@ -209,7 +209,7 @@ module Crystal

if target.is_a?(Path)
const = target.target_const.not_nil!
return node unless const.used
return node unless const.used?
end

node.value = node.value.transform self
4 changes: 1 addition & 3 deletions src/compiler/crystal/semantic/restrictions.cr
Original file line number Diff line number Diff line change
@@ -802,9 +802,7 @@ module Crystal

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

including_types.try &.restrict(other, context)
super || including_types.try(&.restrict(other, context))
end
end

14 changes: 14 additions & 0 deletions src/compiler/crystal/semantic/type_merge.cr
Original file line number Diff line number Diff line change
@@ -257,6 +257,20 @@ module Crystal
end
end

class ProcInstanceType
def common_ancestor(other : ProcInstanceType)
if return_type.no_return? && arg_types == other.arg_types
return other
end

if other.return_type.no_return? && arg_types == other.arg_types
return self
end

nil
end
end

class TupleInstanceType
def common_ancestor(other : TupleInstanceType)
return nil unless self.size == other.size
5 changes: 3 additions & 2 deletions src/compiler/crystal/types.cr
Original file line number Diff line number Diff line change
@@ -2834,7 +2834,7 @@ module Crystal
getter scope_types : Array(Type)
getter scope : Type?
property vars : MetaVars?
property used : Bool
property? used : Bool
property? visited : Bool
property visitor : BaseTypeVisitor?

@@ -3140,7 +3140,8 @@ module Crystal

def implements?(other : Type)
if other.is_a?(ProcInstanceType)
if other.return_type.void? && arg_types == other.arg_types
if (self.return_type.no_return? || other.return_type.void?) &&
arg_types == other.arg_types
return true
end
end