Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler: use freeze_type as node type if node doesn't have a type #7161

Merged
merged 1 commit into from
Dec 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions spec/compiler/semantic/block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1404,4 +1404,32 @@ describe "Block inference" do
i
), inject_primitives: false) { int32 }
end

it "can infer block type given that the method has a return type (#7160)" do
assert_type(%(
struct Int32
def self.foo
0
end
end

class Node
@child : Node?

def sum : Int32
if child = @child
child.call(&.sum)
else
0
end
end

def call(&block : self -> T) forall T
T.foo
end
end

Node.new.sum
)) { int32 }
end
end
4 changes: 2 additions & 2 deletions src/compiler/crystal/semantic/bindings.cr
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@ module Crystal
@type : Type?

def type
@type || ::raise "BUG: `#{self}` at #{self.location} has no type"
type? || ::raise "BUG: `#{self}` at #{self.location} has no type"
end

def type?
@type
@type || @freeze_type
end

def type(*, with_literals = false)
Expand Down