Skip to content
New issue

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

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

Already on GitHub? # to your account

parsing failure for multi-line macro calls and + #20258

Closed
stevengj opened this issue Jan 26, 2017 · 3 comments
Closed

parsing failure for multi-line macro calls and + #20258

stevengj opened this issue Jan 26, 2017 · 3 comments
Labels
bug Indicates an unexpected problem or unintended behavior parser Language parsing and surface syntax

Comments

@stevengj
Copy link
Member

Normally, if you type an incomplete binary expression like 1 + 1 +, then the parser automatically looks to the next line to complete the expression. However, this doesn't happen in macro calls (in both Julia 0.5 and 0.6):

julia> 1 + 1 +
       1
3

julia> Base.Test.@test 1 + 1 +
ERROR: MethodError: no method matching @test(::Expr, ::Symbol)
Closest candidates are:
  @test(::ANY) at test.jl:189

It seems to be related to the fact that + is both a binary and a unary operator, since it works fine for *, and hence I think it is a bug:

julia> Base.Test.@test 1 * 1 *
       1 == 1
Test Passed
  Expression: 1 * 1 * 1 == 1
   Evaluated: 1 == 1

(I got bitten by this in #20249 when .+ became a unary+binary operator.)

@stevengj stevengj added bug Indicates an unexpected problem or unintended behavior parser Language parsing and surface syntax labels Jan 26, 2017
@TotalVerb
Copy link
Contributor

This seems to happen in all white-space sensitive contexts. For example

julia> [1 +
        1 2]
2×2 Array{Any,2}:
 1   +
 1  2 
julia> [1 +
        1]
ERROR: ArgumentError: number of columns of each array must match (got (2,1))
 in typed_vcat(::Type{Any}, ::Array{Any,2}, ::Array{Int64,2}) at ./abstractarray.jl:1039
 in vcat(::Array{Any,2}, ::Array{Int64,2}) at ./array.jl:726
 in hvcat(::Tuple{Int64,Int64}, ::Int64, ::Vararg{Any,N}) at ./abstractarray.jl:1361

@TotalVerb
Copy link
Contributor

TotalVerb commented Jan 26, 2017

A "workaround" is to append a trailing whitespace

julia> @test 1 + ## note: there is a trailing space here
       1 == 2
Test Passed
  Expression: 1 + 1 == 2
   Evaluated: 2 == 2

@TotalVerb
Copy link
Contributor

I thought this was familiar. This has already been reported at #16594.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
bug Indicates an unexpected problem or unintended behavior parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

2 participants