-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added:
private def
at the top-level of a file is only available ins…
…ide that file
- Loading branch information
Ary Borenszweig
committed
Jan 2, 2015
1 parent
de1d35f
commit 79805a5
Showing
5 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Codegen: private def" do | ||
it "codegens private def in same file" do | ||
compiler = Compiler.new | ||
sources = [ | ||
Compiler::Source.new("foo.cr", %( | ||
private def foo | ||
1 | ||
end | ||
foo | ||
)), | ||
] | ||
compiler.prelude = "empty" | ||
|
||
tempfile = Tempfile.new("crystal-spec-output") | ||
output_filename = tempfile.path | ||
tempfile.close | ||
|
||
compiler.compile sources, output_filename | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
require "../../spec_helper" | ||
|
||
describe "Type inference: private def" do | ||
it "doesn't find private def in another file" do | ||
expect_raises Crystal::TypeException, "undefined local variable or method 'foo'" do | ||
compiler = Compiler.new | ||
sources = [ | ||
Compiler::Source.new("foo.cr", %( | ||
private def foo | ||
1 | ||
end | ||
)), | ||
Compiler::Source.new("bar.cr", %( | ||
foo | ||
)), | ||
] | ||
compiler.no_build = true | ||
compiler.prelude = "empty" | ||
compiler.compile sources, "output" | ||
end | ||
end | ||
|
||
it "finds private def in same file" do | ||
compiler = Compiler.new | ||
sources = [ | ||
Compiler::Source.new("foo.cr", %( | ||
private def foo | ||
1 | ||
end | ||
foo | ||
)), | ||
] | ||
compiler.no_build = true | ||
compiler.prelude = "empty" | ||
compiler.compile sources, "output" | ||
end | ||
|
||
it "finds private def in same file that invokes another def" do | ||
compiler = Compiler.new | ||
sources = [ | ||
Compiler::Source.new("foo.cr", %( | ||
def bar | ||
2 | ||
end | ||
private def foo | ||
bar | ||
end | ||
foo | ||
)), | ||
] | ||
compiler.no_build = true | ||
compiler.prelude = "empty" | ||
compiler.compile sources, "output" | ||
end | ||
|
||
it "types private def correctly" do | ||
assert_type(%( | ||
private def foo | ||
1 | ||
end | ||
def foo | ||
'a' | ||
end | ||
foo | ||
)) { int32 } | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters