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 issue for composed return value with => #25391

Closed
KlausC opened this issue Jan 4, 2018 · 3 comments
Closed

Parsing issue for composed return value with => #25391

KlausC opened this issue Jan 4, 2018 · 3 comments
Assignees
Labels
parser Language parsing and surface syntax
Milestone

Comments

@KlausC
Copy link
Contributor

KlausC commented Jan 4, 2018

julia> f1() = begin 0:-1, ""=>"" end;

julia> f2() = begin (0:-1, ""=>"") end;

I expected the same return type for both functions, but:

julia> typeof(f1())
Pair{Tuple{UnitRange{Int64},String},String}

julia> typeof(f2())
Tuple{UnitRange{Int64},Pair{String,String}}

julia> typeof((0:-1, ""=>""))
Tuple{UnitRange{Int64},Pair{String,String}}

julia> typeof(((0:-1, ""=>"")))
Tuple{UnitRange{Int64},Pair{String,String}}

julia> typeof(((0:-1, "")=>""))
Pair{Tuple{UnitRange{Int64},String},String}

It looks like the comma "operator" in a,b has precedence before the => operator.
IMO that is not to be expected and a parsing issue, because the consequence is, that parens
around an expression can change the meaning.
With my restricted insight, I cannot imagine a reason for comma needing a high precedence, when
it appears outside a parenthesized list.

PS: its the same with assignments x1 = 0:-1, ""=>"" etc.

@JeffBezanson JeffBezanson added the parser Language parsing and surface syntax label Jan 11, 2018
@JeffBezanson
Copy link
Sponsor Member

The reason for this is to parse a, b = c as (a, b) = c, and => has traditionally had assignment-like precedence. There is some history in #12285. The most recent suggestion is to give => its own precedence level higher than = but lower than everything else. That was never done, but maybe we should do it now? I kind of like the idea.

@JeffBezanson JeffBezanson self-assigned this Jan 11, 2018
@JeffBezanson JeffBezanson changed the title Parsing / Type issue for composed return value Parsing issue for composed return value Jan 11, 2018
@JeffBezanson JeffBezanson changed the title Parsing issue for composed return value Parsing issue for composed return value with => Jan 11, 2018
@JeffBezanson
Copy link
Sponsor Member

That change would only break a => b = c, which I imagine is basically never used. It currently parses as a => (b = c), which is weird, since (a => b) = c would be more useful (for destructuring).

@JeffBezanson JeffBezanson added the status:triage This should be discussed on a triage call label Jan 11, 2018
@KlausC
Copy link
Contributor Author

KlausC commented Jan 11, 2018

I had the idea, that arith/logical ops stronger => stronger than , stronger than = outside of argument lists/tuples.
Inside argument lists, => stronger = stronger , .
That would have the effect, that expressions not containing = or less binding did not change meaning, if wrapped into () - they remained tuples, if separated by ,.

@JeffBezanson JeffBezanson added this to the 1.0 milestone Jan 11, 2018
@StefanKarpinski StefanKarpinski removed the status:triage This should be discussed on a triage call label Jan 11, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
parser Language parsing and surface syntax
Projects
None yet
Development

No branches or pull requests

3 participants