I believe the problem comes from `"{"` which actually starts an
interpolated code block containing a string immediately. That's also why
it doesn't complain about the "else" being in an odd place; it's also
inside the string!
So here's an equivalent piece of code that shows what's wrong:
if request.body[0] == "" ~ do { qq⟨{ say "JSON"} else {say "NOTJSON"};
# my %bb = 1234 => 99;
(and here comes the closing quote for the qq that was missing in the original
code: ⟩
Simplifying a tiny bit more:
if request.body[0] == "" ~ (say "JSON") ~ " else " ~ (say "NOTJSON") ~ ";
# my %bb = 1234 => 99;
again no closing double-quotes
Does that help?
On 25/01/2019 07:20, Aleks-Daniel Jakimenko-Aleksejev via RT wrote:
> Usually this happens when you have an unclosed string somewhere earlier in
> your
> code.
>
> That is:
>
> say "foo; ← oops! Forgot the closing "
>
> # $a ← we think that this is a comment, but actually it's part of the string
> above!
> On 2019-01-23 01:27:08, [email protected] wrote:
>> Hello:
>>
>> I ran into this while setting up a post test for json
>> in bailador. While compiling it flags the commented
>> line at the end as bad when the fail should be on the
>> check of request.body[0].
>>
>> It happened with the latest rakudo built from scratch
>> as of Jan 23rd 2019 as well as rakudo-star 2018.10.
>>
>> Linux Mint system, 64 bit.
>>
>>
>>
>>
>> # --->perl6 t1.pl6
>> # ===SORRY!=== Error while compiling
>> /home/userx/p6d/tests/latester/t1.pl6
>> # Variable '%bb' is not declared
>> # at /home/userx/p6d/tests/latester/t1.pl6:97
>> # ------> #pukes here #say ⏏%bb{"name"};
>>
>> # code snippet that causes the parser to think
>> # the commented code below is not commented
>> if request.body[0] == "{" { say "JSON"} else {say "NOTJSON"};
>>
>> # #my %bb = from-json(request.body);
>> #
>> # this one pukes
>> #pukes here #say %bb{"name"};