Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

parsing ambiguity of .! ? #20541

Closed
Sacha0 opened this issue Feb 9, 2017 · 6 comments
Closed

parsing ambiguity of .! ? #20541

Sacha0 opened this issue Feb 9, 2017 · 6 comments
Labels
domain:broadcast Applying a function over a collection kind:bug Indicates an unexpected problem or unintended behavior parser Language parsing and surface syntax
Milestone

Comments

@Sacha0
Copy link
Member

Sacha0 commented Feb 9, 2017

With

julia> versioninfo()
Julia Version 0.6.0-dev.2673
Commit e24faa5* (2017-02-08 21:01 UTC)
Platform Info:
  OS: macOS (x86_64-apple-darwin15.6.0)
  CPU: Intel(R) Core(TM) i7-3520M CPU @ 2.90GHz
  WORD_SIZE: 64
  BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NO_AFFINITY Sandybridge)
  LAPACK: libopenblas64_
  LIBM: libopenlibm
  LLVM: libLLVM-3.9.1 (ORCJIT, ivybridge)

julia> [[true] !([true])]
1×2 Array{Bool,2}:
 true  false

I expected [[true] .!([true])] to function identically, but instead this yields a binary ! broadcast

julia> [[true] .!([true])]
ERROR: MethodError: no method matching !(::Bool, ::Bool)
Closest candidates are:
  !(::Bool) at bool.jl:36
Stacktrace:
 [1] broadcast_t(::Function, ::Type{Any}, ::Tuple{Base.OneTo{Int64}}, ::CartesianRange{CartesianIndex{1}}, ::Array{Bool,1}, ::Array{Bool,1}) at ./broadcast.jl:255
 [2] broadcast_c at ./broadcast.jl:298 [inlined]
 [3] broadcast(::Function, ::Array{Bool,1}, ::Array{Bool,1}) at ./broadcast.jl:406

julia> expand(:([[true] .!([true])]))
:((Base.vect)((Base.broadcast)(!, (Base.vect)(true), (Base.vect)(true))))

likewise e.g.

julia> [true .!true]
ERROR: MethodError: no method matching !(::Bool, ::Bool)
Closest candidates are:
  !(::Bool) at bool.jl:36
Stacktrace:
 [1] (::##7#8)(::Bool) at ./<missing>:0
 [2] broadcast(::Function, ::Bool) at ./broadcast.jl:16

Am I making a mistake, or is this a parsing issue? cc @stevengj. Best!

@Sacha0 Sacha0 added the domain:broadcast Applying a function over a collection label Feb 9, 2017
@Sacha0 Sacha0 changed the title parsing ambiguity of .! parsing ambiguity of .! ? Feb 9, 2017
@Sacha0
Copy link
Member Author

Sacha0 commented Feb 9, 2017

(Discovered from failure when writing @deprecate !(B::BitArray) .!B.)

@stevengj
Copy link
Member

stevengj commented Feb 9, 2017

Seems like a parsing issue, since [1 .+1] parses as [1 (.+1)] I think the same should be true for other unary operators.

Actually, it's stronger than that: since ! is only a unary operator, it should parse as unary regardless of the spacing.

@stevengj stevengj added the parser Language parsing and surface syntax label Feb 9, 2017
@Sacha0
Copy link
Member Author

Sacha0 commented Feb 9, 2017

Actually, it's stronger than that: since ! is only a unary operator, it should parse as unary regardless of the spacing.

Agreed, I am confused why .! parses as binary in some cases. Perhaps

(append! '(|<:| |>:| |.!| in isa)
, from 814c974?

@stevengj stevengj added the kind:bug Indicates an unexpected problem or unintended behavior label Feb 9, 2017
@stevengj
Copy link
Member

stevengj commented Feb 9, 2017

I'm marking this as a bug, since .! should never parse as a binary operator.

@stevengj
Copy link
Member

stevengj commented Feb 9, 2017

Yes, it seems like .! should be removed from prec-comparison

@stevengj
Copy link
Member

stevengj commented Feb 9, 2017

Ah, now I see why it is there: see #17393 (comment)

This hack should have been removed when .! was parsed as a unary operator. Can you submit the one-line PR (+ test) to remove .! from prec-comparison?

@stevengj stevengj added this to the 0.6.0 milestone Feb 9, 2017
JeffBezanson added a commit that referenced this issue Feb 11, 2017
fix #20541, remove `.!` from prec-comparison
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
domain:broadcast Applying a function over a collection kind:bug Indicates an unexpected problem or unintended behavior parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants