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
[PATCH] Test to see if hash values are eagerly created #15378
Comments
From oainikusama@gmail.comHi everyone, I have spoken to Zefram and TonyC on #p5p, and apparently it's not well Function arguments are usually taken by value but there's no type Hope it helps :) garu |
From oainikusama@gmail.com0001-Test-to-see-if-hash-values-are-eagerly-created.patchFrom d43d62c3f2f94c54e8f2ac85bd9d4965bb5d16c9 Mon Sep 17 00:00:00 2001
From: "Breno G. de Oliveira" <garu@cpan.org>
Date: Mon, 30 May 2016 23:56:57 -0300
Subject: [PATCH] Test to see if hash values are eagerly created
It's not well documented which operations will eagerly create hash
elements. In foo(\$x{bla}), for example, the \ is treating its
operand as an lvalue, same as if it were on the lhs of an assignment
like that. Now, foo($x{bla}) *also* treats $x{bla} as an lvalue, but
doesn't eagerly create it. Instead, it passes a PVLV to foo(), which
can then create the hash element by assigning to $_[0].
Function arguments are usually taken by value but there's no type
information to say which arguments specifically are taken by
reference and so need the lvalue treatment. This patch adds two
extra tests for that behaviour, so at least they remain consistent.
---
t/op/ref.t | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/t/op/ref.t b/t/op/ref.t
index 19a44bb..4752b9f 100644
--- a/t/op/ref.t
+++ b/t/op/ref.t
@@ -8,7 +8,7 @@ BEGIN {
use strict qw(refs subs);
-plan(235);
+plan(237);
# Test this first before we extend the stack with other operations.
# This caused an asan failure due to a bad write past the end of the stack.
@@ -114,6 +114,15 @@ is (join(':',@{$spring[5]}), "123:456:789");
$spring2{"foo"}->[3] = 4;
is (join(':',@{$spring2{"foo"}}), "1:2:3:4");
+# Test to see if hash values are eagerly created
+{
+ sub myspringersub {}
+ myspringersub($spring3{"foo"});
+ is (scalar keys %spring3, 0, 'regular key was not eagerly created after sub call');
+ myspringersub(\$spring3{"foo"});
+ ok (exists $spring3{"foo"}, 'referenced key was eagerly created after sub call');
+}
+
# Test references to subroutines.
{
--
2.5.1
|
From @jkeenanOn Tue May 31 05:29:03 2016, oainikusama@gmail.com wrote:
Here's the commit message: ##### Function arguments are usually taken by value but there's no type ... and here are the added tests: ##### Now, there's a lot of analysis packed into that commit message -- but I'm not sure that all of it is reflected in the tests. The commit message has two paragraphs. The first focuses on lvalues; the second on function arguments. The tests seem to me to focus only on the second. I don't think there is anything really *wrong* here -- but I wonder if the combination of the commit message and the tests really clarifies the issue for people (like me) who are not experts in the perlguts. Thank you very much. -- |
The RT System itself - Status changed from 'new' to 'open' |
From zefram@fysh.orgJames E Keenan via RT wrote:
Yes. The commit message is mostly a rearrangement of comments I made Furthermore, the form of the test code suggests some misunderstanding I approve of adding tests for this part of the language, but we should do -zefram |
From zefram@fysh.orgI wrote:
Here's some code to be thinking about: sub noop { } my %a; my %b; my %c; my @a; my @b; my @c; -zefram |
From @demerphqOn 31 May 2016 at 14:29, B O <perlbug-followup@perl.org> wrote:
While I think its useful to have some kind of testing for this I am fine if we write a bunch of tests which becomes an assay of the Hope that makes sense. I do appreciate the thought and effort that Yves -- |
From zefram@fysh.orgdemerphq wrote:
No, it's long-standing behaviour. Probably all the way back to 5.000, -zefram |
From @demerphqOn 1 June 2016 at 11:32, Zefram <zefram@fysh.org> wrote:
A bug that lives long enough is a feature? I don't think that is the Yves -- |
From zefram@fysh.orgdemerphq wrote:
A bug that lives long enough may be troublesome to fix. In this case If you want to change it, presumably you wouldn't want to make If all you want is for a lazy version of \$x{bla} to be available, that -zefram |
From zefram@fysh.orgYves sent a reply directly to me, but has clarified privately that he
-zefram |
From @cpansproutOn Thu Jun 02 13:31:51 2016, zefram@fysh.org wrote:
$ ack normative t t/mro/package_aliases_utf8.t t/op/join.t t/op/sub_lval.t I’m responsible for most of those. :-)
I’ve also fixed broken tests. If there is consensus that the tests are wrong, we can change (or delete) them. -- Father Chrysostomos |
From @demerphqOn 2 June 2016 at 22:57, Father Chrysostomos via RT
I am responsible for some, but Iacked the foresight to choose a Yves -- |
Migrated from rt.perl.org#128301 (status was 'open')
Searchable as RT128301$
The text was updated successfully, but these errors were encountered: