Skip to content

Commit

Permalink
Merge remote-tracking branch 'foreign/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
ozra committed Sep 22, 2016
2 parents 96647b5 + 50cee13 commit 08c1fcc
Show file tree
Hide file tree
Showing 68 changed files with 594 additions and 516 deletions.
1 change: 1 addition & 0 deletions ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

Make sure to review these points before submitting issues - thank you!

- Make sure a similar issue doesn't exist yet: use the search box
- **Include reproducible code**: we should be able to paste it into an editor, compile and run it and get the same error as you. Otherwise it's impossible for us to reproduce the bug.
- Don't **only** use `play.crystal-lang.org` or `carc.in`: code might be lost and the issue will remain incomplete. Write code in the issue itself.
- Reduce code, if possible, to the minimum size that reproduces the bug.
Expand Down
6 changes: 3 additions & 3 deletions bin/ci
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ EOF
prepare_build() {
on_linux verify_linux_environment

on_linux docker pull "jhass/crystal-build-$ARCH:llvm38"
on_linux docker pull "jhass/crystal-build-$ARCH"

on_osx brew install llvm libevent pcre crystal-lang
}
Expand All @@ -165,7 +165,7 @@ with_build_env() {
-v $(pwd):/mnt \
-w /mnt \
-e LIBRARY_PATH="/opt/crystal/embedded/lib/" \
"jhass/crystal-build-$ARCH:llvm38" \
"jhass/crystal-build-$ARCH" \
"$ARCH_CMD" /bin/bash -c "'$command'"

on_osx PATH="/usr/local/opt/llvm/bin:\$PATH" \
Expand Down Expand Up @@ -219,4 +219,4 @@ case $command in
exit 1
fi
;;
esac
esac
12 changes: 12 additions & 0 deletions spec/compiler/codegen/private_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,16 @@ describe "Codegen: private" do

compiler.compile sources, output_filename
end

it "doesn't include filename for private types" do
run(%(
private class Foo
def foo
{{@type.stringify}}
end
end

Foo.new.foo
), filename: "foo").to_string.should eq("Foo")
end
end
5 changes: 5 additions & 0 deletions spec/compiler/parser/to_s_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,9 @@ describe "ASTNode#to_s" do
expect_to_s "1e10_f64", "1e10"
expect_to_s "!a"
expect_to_s "!(1 < 2)"
expect_to_s "(1 + 2)..3"
expect_to_s "macro foo\n{{ @type }}\nend"
expect_to_s "macro foo\n\\{{ @type }}\nend"
expect_to_s "macro foo\n{% @type %}\nend"
expect_to_s "macro foo\n\\{%@type %}\nend"
end
47 changes: 47 additions & 0 deletions spec/compiler/semantic/block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -1298,4 +1298,51 @@ describe "Block inference" do
end
)) { union_of(int32, int64) }
end

it "uses free var in return type in captured block" do
assert_type(%(
class U
end

def foo(&block : -> U) forall U
block
U
end

foo { 1 }
)) { int32.metaclass }
end

it "uses free var in return type with tuple type" do
assert_type(%(
class T; end

class U; end

class Foo(T)
def initialize(@x : T)
end

def foo(&block : T -> U) forall U
{yield(@x), U}
end
end

Foo.new(1).foo { |x| {x, x} }
)) { tuple_of([tuple_of([int32, int32]), tuple_of([int32, int32]).metaclass]) }
end

it "correctly types unpacked tuple block arg after block (#3339)" do
assert_type(%(
def foo
yield({""})
end

i = 1
foo do |(i)|

end
i
), inject_primitives: false) { int32 }
end
end
2 changes: 1 addition & 1 deletion spec/compiler/semantic/def_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ describe "Semantic: def" do

it "accesses free var of default argument (#1101)" do
assert_type(%(
def foo(x, y : U = nil)
def foo(x, y : U = nil) forall U
U
end

Expand Down
16 changes: 16 additions & 0 deletions spec/compiler/semantic/macro_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -918,4 +918,20 @@ describe "Semantic: macro" do
->(x : Int32) { foo(x) }.call(1)
)) { int32 }
end

it "applies visibility modifier only to first level" do
assert_type(%(
macro foo
class Foo
def self.foo
1
end
end
end

private foo

Foo.foo
), inject_primitives: false) { int32 }
end
end
4 changes: 2 additions & 2 deletions spec/std/array_spec.cr
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
require "spec"

alias RecursiveArray = Array(RecursiveArray)
private alias RecursiveArray = Array(RecursiveArray)

class BadSortingClass
private class BadSortingClass
include Comparable(self)

def <=>(other)
Expand Down
19 changes: 18 additions & 1 deletion spec/std/base64_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "base64"
require "crypto/md5"

describe "Base64" do
it "simple test" do
context "simple test" do
eqs = {"" => "", "a" => "YQ==\n", "ab" => "YWI=\n", "abc" => "YWJj\n",
"abcd" => "YWJjZA==\n", "abcde" => "YWJjZGU=\n", "abcdef" => "YWJjZGVm\n",
"abcdefg" => "YWJjZGVmZw==\n"}
Expand All @@ -18,6 +18,18 @@ describe "Base64" do
end
end

context "\n in multiple places" do
eqs = {"abcd" => "YWJj\nZA==\n", "abcde" => "YWJj\nZGU=\n", "abcdef" => "YWJj\nZGVm\n",
"abcdefg" => "YWJj\nZGVmZw==\n", "abcdefg" => "YWJj\nZGVm\nZw==\n",
}
eqs.each do |a, b|
it "decode from #{b.inspect} to #{a.inspect}" do
Base64.decode(b).should eq(a.to_slice)
Base64.decode_string(b).should eq(a)
end
end
end

it "encodes byte slice" do
slice = Slice(UInt8).new(5) { 1_u8 }
Base64.encode(slice).should eq("AQEBAQE=\n")
Expand Down Expand Up @@ -130,6 +142,11 @@ describe "Base64" do
Base64.decode_string("a")
end
end

it "decode small tail after last \n, was a bug" do
s = "Tm93IGlzIHRoZSB0aW1lIGZvciBhbGwgZ29vZCBjb2RlcnMKdG8gbGVhcm4g\nnA==\n"
Base64.decode(s).should eq Bytes[78, 111, 119, 32, 105, 115, 32, 116, 104, 101, 32, 116, 105, 109, 101, 32, 102, 111, 114, 32, 97, 108, 108, 32, 103, 111, 111, 100, 32, 99, 111, 100, 101, 114, 115, 10, 116, 111, 32, 108, 101, 97, 114, 110, 32, 156]
end
end

describe "scrict" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/comparable_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec"

class ComparableTestClass
private class ComparableTestClass
include Comparable(Int)

def initialize(@value : Int32)
Expand Down
4 changes: 2 additions & 2 deletions spec/std/deque_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec"

class DequeTester
private class DequeTester
# Execute the same actions on an Array and a Deque and compare them at each step.

@deque : Deque(Int32)
Expand Down Expand Up @@ -34,7 +34,7 @@ class DequeTester
end
end

alias RecursiveDeque = Deque(RecursiveDeque)
private alias RecursiveDeque = Deque(RecursiveDeque)

describe "Deque" do
describe "implementation" do
Expand Down
2 changes: 1 addition & 1 deletion spec/std/ecr/ecr_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ require "spec"
require "ecr"
require "ecr/processor"

class ECRSpecHelloView
private class ECRSpecHelloView
@msg : String

def initialize(@msg)
Expand Down
2 changes: 1 addition & 1 deletion spec/std/enumerable_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec"

class SpecEnumerable
private class SpecEnumerable
include Enumerable(Int32)

def each
Expand Down
2 changes: 1 addition & 1 deletion spec/std/exception_spec.cr
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
require "spec"

class FooError < Exception
private class FooError < Exception
def message
"#{super || ""} -- bar!"
end
Expand Down
28 changes: 13 additions & 15 deletions spec/std/hash_spec.cr
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
require "spec"

module HashSpec
alias RecursiveHash = Hash(RecursiveHash, RecursiveHash)
private alias RecursiveHash = Hash(RecursiveHash, RecursiveHash)

class HashBreaker
getter x : Int32
private class HashBreaker
getter x : Int32

def initialize(@x)
end
end

class NeverInstantiated
def initialize(@x)
end
end

alias RecursiveType = String | Int32 | Array(RecursiveType) | Hash(Symbol, RecursiveType)
private class NeverInstantiated
end

private alias RecursiveType = String | Int32 | Array(RecursiveType) | Hash(Symbol, RecursiveType)

describe "Hash" do
describe "empty" do
it "size should be zero" do
Expand Down Expand Up @@ -284,7 +282,7 @@ describe "Hash" do
assert { {1 => 2, 3 => 4}.to_s.should eq("{1 => 2, 3 => 4}") }

assert do
h = {} of HashSpec::RecursiveHash => HashSpec::RecursiveHash
h = {} of RecursiveHash => RecursiveHash
h[h] = h
h.to_s.should eq("{{...} => {...}}")
end
Expand Down Expand Up @@ -342,7 +340,7 @@ describe "Hash" do
end

it "merges recursive type (#1693)" do
hash = {:foo => "bar"} of Symbol => HashSpec::RecursiveType
hash = {:foo => "bar"} of Symbol => RecursiveType
result = hash.merge({:foobar => "foo"})
result.should eq({:foo => "bar", :foobar => "foo"})
end
Expand Down Expand Up @@ -516,13 +514,13 @@ describe "Hash" do
end

it "fetches from empty hash with default value" do
x = {} of Int32 => HashSpec::HashBreaker
breaker = x.fetch(10) { HashSpec::HashBreaker.new(1) }
x = {} of Int32 => HashBreaker
breaker = x.fetch(10) { HashBreaker.new(1) }
breaker.x.should eq(1)
end

it "does to to_s with instance that was never instantiated" do
x = {} of Int32 => HashSpec::NeverInstantiated
x = {} of Int32 => NeverInstantiated
x.to_s.should eq("{}")
end

Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/client/client_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ require "openssl"
require "http/client"
require "http/server"

class TestServer < TCPServer
private class TestServer < TCPServer
def self.open(host, port, read_time = 0)
server = new(host, port)
begin
Expand Down
2 changes: 1 addition & 1 deletion spec/std/http/server/handlers/handler_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "spec"
require "http/server"

class EmptyHTTPHandler < HTTP::Handler
private class EmptyHTTPHandler < HTTP::Handler
def call(context)
call_next(context)
end
Expand Down
Loading

0 comments on commit 08c1fcc

Please sign in to comment.