I don't really want to start another ticket for what I'm about to suggest, therefore I'll reopen this one.
Not so long ago I filed this ticket: https://rt.perl.org/Ticket/Display.html?id=131640 The underlying issue is exactly the same. And it has actually happened during whateverable development, so it is not some kind of a thought exercise. Therefore, I think that we should actually try to improve the error message somehow. And here's my idea. What if the error message said something like this: ===SORRY!=== Error while compiling -e Cannot use variable $number in declaration to initialize itself (while parsing shell-quote words started at line 2) at -e:3 ------> put "Type: " ~ $⏏number; expecting any of: double quotes statement end statement modifier statement modifier loop term Please suggest a better way to put it, but the idea is quite simple: if we are inside another language that was started on a different line, why not say where exactly it was started? There may be cases when this additional line will not give anything useful, but generally it will make the error message Truly Awesome™. On 2017-07-03 10:59:54, allber...@gmail.com wrote: > Perhaps this example should be provided somewhere as a 'gotcha'. > > On Mon, Jul 3, 2017 at 11:09 AM, jn...@jnthn.net via RT < > perl6-bugs-follo...@perl.org> wrote: > > > On Mon, 03 Jul 2017 05:46:46 -0700, comdog wrote: > > > It seems that term precedence with << >> gets confused. > > > > > The << >> quoting construct interpolates. The rule for interpolation > > of > > method calls, indexing, etc. after a scalar is that there may be one, > > but > > it may only end with a ], ), } or >. > > > > > { > > > my $number = <<$string>>[0]; > > > > When the variable is encountered inside of the interpolating quoting > > construct, which is being parsed by the quoting parser, it calls back > > into > > the Perl 6 main language parser. This parses a variable and > > optionally a > > postfix. The >>[0] is a valid postfix, where >> is the hyper-operator > > and > > [0] is the indexer. Therefore the $string>>[0] is taken as the thing > > to > > interpolate. It then hands back control to the quoting parser. > > > > > put "Type: " ~ $number; > > > #`( > > > ===SORRY!=== Error while compiling ... > > > Cannot use variable $number in declaration to initialize itself > > > ------> put "Type: " ~ $⏏number; > > > > This is complaining that $number was used before its declaration was > > complete, which is indeed the case because at we are still inside of > > the > > quoting construct. > > > > I can see the potential for a human reader to be confused, but the > > Perl 6 > > parser is not in the least bit confused. There isn't any question as > > to > > what will parse the >>: if the main language parser understands it > > and > > wants it, then it gets it, because the quoting parser doesn't get a > > say > > again until the main language parser has done its bit. This is the > > same > > reason that you can do stuff like: > > > > say "Foos: @foo.join("bar")" > > > > And there isn't a bit of confusion so far as Perl 6 is concerned that > > the > > inner " is opening a new string, not closing the one we were already > > in. > > Granted it's maybe kinder to the reader to write it with single > > quotes > > inside of the string. But nestings of main language => quote parser > > => main > > language => quote parser will Just Work, each eating as much as it > > understands (or until seeing its terminator) before giving up > > control. > > > > /jnthn > > > >