Skip to content

Commit

Permalink
Allow invoking lib call without obj inside lib. Part of #311
Browse files Browse the repository at this point in the history
  • Loading branch information
Ary Borenszweig committed Dec 19, 2014
1 parent b2ecb03 commit e514d12
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
12 changes: 12 additions & 0 deletions spec/compiler/type_inference/lib_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -307,4 +307,16 @@ it "errors if unknown named arg" do
1
)) { int32 }
end

it "allows invoking lib call without obj inside lib" do
assert_type(%(
lib Foo
fun foo : Int32
A = foo
end
Foo::A
)) { int32 }
end
end
9 changes: 7 additions & 2 deletions src/compiler/crystal/semantic/call.cr
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,15 @@ class Crystal::Call
if obj_type.is_a?(LibType)
recalculate_lib_call obj_type
return
elsif !obj || obj_type
check_not_lib_out_args
end

if !obj && (lib_type = scope()).is_a?(LibType)
recalculate_lib_call lib_type
return
end

check_not_lib_out_args

if args.any? &.type?.try &.no_return?
set_type mod.no_return
return
Expand Down

0 comments on commit e514d12

Please sign in to comment.