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

rakudo dies when Ternary Error occurs #1087

Closed
p6rt opened this issue Jun 22, 2009 · 7 comments
Closed

rakudo dies when Ternary Error occurs #1087

p6rt opened this issue Jun 22, 2009 · 7 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jun 22, 2009

Migrated from rt.perl.org#66840 (status was 'resolved')

Searchable as RT66840$

@p6rt
Copy link
Author

p6rt commented Jun 22, 2009

From amoc.yn@gmail.com

at revision​: 1b06df80900096dab8a9f74467f504f73a6115dd
and also at release #​18.

: bash$ perl6
: > 1 ?? 2 !! 3
: > 1 ?? (1,2) !! (3,4)
: > 1 ?? 1,2 !! 3,4
: Ternary error
: bash$

this is not wrong as infix​:<,> has looser precedence than the ternary
operator( ?? !! )
but when ternary error occurs, the program emits the error and dies.

should provide the proper error message and not die.

@p6rt
Copy link
Author

p6rt commented Jun 22, 2009

From amoc.yn@gmail.com

from S03​:
http://perlcabal.org/syn/S03.html#Conditional_operator_precedence

: It is a syntax error to use an operator in the middle part that binds
looser in precedence, such as =.

: my $x;
: hmm() ?? $x = 1 !! $x = 2; # ERROR
: hmm() ?? ($x = 1) !! ($x = 2); # works

@p6rt
Copy link
Author

p6rt commented Jun 22, 2009

From @kyleha

By my reading, it really is an error, not valid code. The infix​:<,> is
looser than the ternary, as you say, so without parens, it parses as​:

(1 ?? 1),(2 !! 3),4

I agree, however, that this shouldn't die.

I've added a test for this in t/spec/S03-operators/ternary.t

Thanks.

Kyle.

On Mon, Jun 22, 2009 at 1​:57 AM, Hojung Yoon
<perl6-bugs-followup@​perl.org>wrote​:

# New Ticket Created by Hojung Yoon
# Please include the string​: [perl #​66840]
# in the subject line of all future correspondence about this issue.
# <URL​: http://rt.perl.org/rt3/Ticket/Display.html?id=66840 >

at revision​: 1b06df80900096dab8a9f74467f504f73a6115dd
and also at release #​18.

: bash$ perl6
: > 1 ?? 2 !! 3
: > 1 ?? (1,2) !! (3,4)
: > 1 ?? 1,2 !! 3,4
: Ternary error
: bash$

this is not wrong as infix​:<,> has looser precedence than the ternary
operator( ?? !! )
but when ternary error occurs, the program emits the error and dies.

should provide the proper error message and not die.

@p6rt
Copy link
Author

p6rt commented Jun 22, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Jun 22, 2009

From john@perlwolf.com

On Mon, Jun 22, 2009 at 04​:59​:07PM +0900, hojung yoon wrote​:

from S03​:
http://perlcabal.org/syn/S03.html#Conditional_operator_precedence

: It is a syntax error to use an operator in the middle part that binds
looser in precedence, such as =.

: my $x;
: hmm() ?? $x = 1 !! $x = 2; # ERROR
: hmm() ?? ($x = 1) !! ($x = 2); # works

This seems like something that is eligible for DWIMery. If the
tokenizer were to automatically turn "??" and "!!" into "?? (" and
") !!", it would permit such constructions. This pair of operators
should be acting like a bracketing pair, and not be especially
susceptible to issues of precedence - it is only the expressions
before the ?? and after the !! that should be affected by the
precedence of the ??!! operator, any expression in between them
should be allowed. (Rather than inserting imaginary parens, it
can be done by treating the precedence of ?? as extremely low when
compared to operators to its right, e.g. -1; and the precedence of
!! as even lower (e.g. -2) when compared to operators on its left.
Operators outside of the ?? ... !! area are compared using the
official precedence of the ??!! operators. (Way back in compiler
construction course I did a similar sort of thing to allow assignment
to be put into the middle of an expression without requiring parens
to bind the lvalue. (E.g. i=10*j=l+m was parsed as i=10*(j=l+m)
with assignment being high precedence over operators to its left
and low precedence to operators on its right.)

@p6rt
Copy link
Author

p6rt commented Jul 1, 2009

From @pmichaud

On Sun Jun 21 23​:57​:17 2009, amoc wrote​:

: bash$ perl6
: > 1 ?? 1,2 !! 3,4
: Ternary error
: bash$

this is not wrong as infix​:<,> has looser precedence than the ternary
operator( ?? !! )
but when ternary error occurs, the program emits the error and dies.

should provide the proper error message and not die.

Now fixed in 5351a33​:

  $ ./perl6
  > 1 ?? 1,2 !! 3,4
  Ternary error at offset 6, found ','
  in Main (src/gen_setting.pm​:3279)
  >

I grant that the error message should be a bit more helpful, but I think
I'll postpone that part for the overall refactor of error message
handling and parsing that will be coming up soon. As shown above, the
ternary error no longer forces an exit.

Closing ticket,

Pm

@p6rt
Copy link
Author

p6rt commented Mar 30, 2010

@moritz - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Mar 30, 2010
@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant