Skip to content

Commit

Permalink
Write :: before formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
bmulvihill authored and asterite committed Jun 6, 2017
1 parent abd2dfd commit 739fc81
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions spec/compiler/formatter/formatter_spec.cr
Expand Up @@ -97,6 +97,11 @@ describe Crystal::Formatter do
assert_format "Foo( x: Int32 )", "Foo(x: Int32)"
assert_format "Foo( x: Int32 , y: Float64 )", "Foo(x: Int32, y: Float64)"

assert_format "::Tuple(T)"
assert_format "::NamedTuple(T)"
assert_format "::Pointer(T)"
assert_format "::StaticArray(T)"

%w(if unless).each do |keyword|
assert_format "#{keyword} a\n2\nend", "#{keyword} a\n 2\nend"
assert_format "#{keyword} a\n2\n3\nend", "#{keyword} a\n 2\n 3\nend"
Expand Down
5 changes: 5 additions & 0 deletions src/compiler/crystal/tools/formatter.cr
Expand Up @@ -986,6 +986,11 @@ module Crystal
name = node.name
first_name = name.global? && name.names.size == 1 && name.names.first

if name.global? && @token.type == :"::"
write "::"
next_token_skip_space_or_newline
end

if node.question?
node.type_vars[0].accept self
write_token :"?"
Expand Down

0 comments on commit 739fc81

Please sign in to comment.