# New Ticket Created by  Brandon Allbery 
# Please include the string:  [perl #125542]
# in the subject line of all future correspondence about this issue. 
# <URL: https://rt.perl.org/Ticket/Display.html?id=125542 >


Inspired by a p6-users message where someone was confused after attempting
to naïvely translate a use of P5ish refs to P6. Possibly the inverse case
(mistaking %(...) for P5's %{...} and similar) should also warn, and
possibly this should be made to only occur once per compilation unit.

(attached)
-- 
brandon s allbery kf8nh                               sine nomine associates
allber...@gmail.com                                  ballb...@sinenomine.net
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
>From 0cdc736294742653b2652923f7fcbe3874daab06 Mon Sep 17 00:00:00 2001
From: brandon s allbery kf8nh <allber...@gmail.com>
Date: Fri, 3 Jul 2015 14:35:54 -0400
Subject: [PATCH] Warn on P5ish use of \ on single sigiled variable

---
 src/Perl6/Grammar.nqp | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/Perl6/Grammar.nqp b/src/Perl6/Grammar.nqp
index 42e8eeb..ac2d7aa 100644
--- a/src/Perl6/Grammar.nqp
+++ b/src/Perl6/Grammar.nqp
@@ -2575,6 +2575,8 @@ grammar Perl6::Grammar is HLL::Grammar does STD {
         '\\'
         [
         | '(' <semiarglist> ')'
+       # catch a common perl5-to-perl6 trap involving references
+        | <?before '$' | '@' | '%'> <.worry("To pass an array or hash to a 
function in Perl 6, just pass it as is, and for other uses of Perl 5's ref 
operator consider binding with ::= instead. Parenthesize as \\(...) if you 
intended a capture of a single variable.")> <termish>
         | <?before \S> <termish>
         | {} <.panic: "You can't backslash that">
         ]
-- 
1.9.1

Reply via email to