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

'my ($a is readonly) = 5' should be allowed, but assigning to it afterward should be disallowed; '(my $a is readonly) = 5' should also be disallowed... in Rakudo #1008

Closed
p6rt opened this issue May 21, 2009 · 10 comments

Comments

@p6rt
Copy link

p6rt commented May 21, 2009

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

Searchable as RT65900$

@p6rt
Copy link
Author

p6rt commented May 21, 2009

From @masak

<masak> rakudo​: my ($a is readonly) = 5; say $a; $a = 42; say $a
<p6eval> rakudo 79d0b9​: OUTPUT«5␤42␤»
<PerlJam> heh
* masak submits rakudobug
<masak> which behaviour do I expect? is the 5 assignment allowed?
<masak> probably not, right?
<TimToady> allowed
<masak> ok.
<TimToady> assignment semantic analyzer always has to look at left
side to see if a declarator governs semantics
<PerlJam> surely the assignment must be allowed. How do you get a
value otherwise?
<masak> PerlJam​: my ($a is readonly = 5)
<TimToady> (my $a is readonly) = 5 would not be allowed
<TimToady> well, probably not
<masak> ok, so _not_ allowed... :)
<PerlJam> masak​: well, there's 3 different initialization forms we
just talked about. Which are you referring to? :)
<TimToady> only my form is disallowed
<TimToady> er
<TimToady> the form I said
<PerlJam> heh
<masak> PerlJam​: the one TimToady just disallowed.
<TimToady> it's like difference between state $x = 0 and (state $x) = 0
<masak> everything you say will be used against you in the bug report :)
<PerlJam> my ($a is readonly, $b is readonly = 5) = 6; # does this work?
<PerlJam> ($a = 6 and $b = 5)
<masak> PerlJam​: not if the '(my $a is readonly) = 5' doesn't work.
<masak> PerlJam​: seems like the same situation with your $a.
<TimToady> no, it's not
<masak> :)
<TimToady> the my is outside
<TimToady> (my vs my (
<masak> oh!
<masak> I missed that!
<masak> important distinction...
<TimToady> I've been saying nothing else for a month
* PerlJam gets masak some TimToady specs
<TimToady> well, a minute, anyway
<masak> sorry, I should pay more attention... :P
<masak> oh, ok. I see now.
<masak> there's no way I can explain this in the bug report save for
quoting the whole thing, misunderstanding and all. :)
<TimToady> consider it an exercise in integrity :)
* masak does that
<masak> rakudo​: (my $a is readonly) = 5; say $a
<p6eval> rakudo 79d0b9​: OUTPUT«5␤»

@p6rt
Copy link
Author

p6rt commented Oct 27, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S06-traits/is-readonly.t

commit 60eb8fe4fe2597318596142bd3268ad9d4b49033
Author​: kyle <kyle@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Tue Oct 27 02​:34​:58 2009 +0000

  [t/spec] Test for RT #​65900
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;28913 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S06-traits/is-readonly.t b/t/spec/S06-traits/is-readonly.t
index 0774abd..389f8a7 100644
--- a/t/spec/S06-traits/is-readonly.t
+++ b/t/spec/S06-traits/is-readonly.t
@@ -4,7 +4,7 @@ use Test;
 # L<S06/"Parameter traits"/"=item is readonly">
 # should be moved with other subroutine tests?
 
-plan 9;
+plan *;
 
 {
     my $a is readonly := 42;
@@ -40,4 +40,16 @@ plan 9;
     ok (try { VAR($a).defined }), ".VAR on a plain normal initialized variable returns true";
 }
 
+# RT #65900
+{
+    my ($rt65900 is readonly) = 5;
+    is $rt65900, 5, 'my ($x is readonly) can take assignment';
+    dies_ok { $rt65900 = 'ro' }, 'dies on assignment to readonly variable';
+
+    dies_ok { (my $rt65900 is readonly) = 5 },
+        'dies on assignment to (my $x is readonly)';
+}
+
+done_testing;
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Oct 27, 2009

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

@p6rt
Copy link
Author

p6rt commented Jun 30, 2010

From @bbkr

$ perl6 -e 'my ($a is readonly) = 5; say $a; $a = 42; say $a'
Cannot assign to readonly value
  in '&infix​:<=>' at line 1
  in main program body at line 1

So it dies properly now.

But test file is not working due to := not implemented in earlier tests.

@p6rt
Copy link
Author

p6rt commented Oct 8, 2011

From @coke

On Wed Jun 30 07​:14​:21 2010, bbkr wrote​:

$ perl6 -e 'my ($a is readonly) = 5; say $a; $a = 42; say $a'
Cannot assign to readonly value
in '&infix​:<=>' at line 1
in main program body at line 1

So it dies properly now.

But test file is not working due to := not implemented in earlier
tests.

Good news​: fudged the test and added it to t/spectest.data so it's run.

Bad news​: I had to fudge these tests too.

--
Will "Coke" Coleda

@p6rt
Copy link
Author

p6rt commented Oct 1, 2014

From @usev6

Things have changed and infix​:<​::=> is used instead of a variable trait "is readonly". The tests for this ticket are gone with this commit​: Raku/roast@253242f

my $a is readonly = 5; say $a;
===SORRY!=== Error while compiling
Can't use unknown trait 'is readonly' in a variable declaration.
at :1
------> my $a is readonly ⏏= 5; say $a;
  expecting any of​:
  TypeObject
  default
  dynamic

(my $a is readonly) = 5; say $a;
Can't use unknown trait 'is readonly' in a variable declaration.
at :1
------> (my $a is readonly⏏) = 5; say $a;
  expecting any of​:
  TypeObject
  default
  dynamic

my ($a is readonly) = 5; say $a; $a++; say $a;
5
6

I think the last one should also result in a compile time error. But I don't know how to fix it.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 1, 2014

From @usev6

Things have changed and infix​:<​::=> is used instead of a variable trait "is readonly". The tests for this ticket are gone with this commit​: Raku/roast@253242f

my $a is readonly = 5; say $a;
===SORRY!=== Error while compiling
Can't use unknown trait 'is readonly' in a variable declaration.
at :1
------> my $a is readonly ⏏= 5; say $a;
  expecting any of​:
  TypeObject
  default
  dynamic

(my $a is readonly) = 5; say $a;
Can't use unknown trait 'is readonly' in a variable declaration.
at :1
------> (my $a is readonly⏏) = 5; say $a;
  expecting any of​:
  TypeObject
  default
  dynamic

my ($a is readonly) = 5; say $a; $a++; say $a;
5
6

I think the last one should also result in a compile time error. But I don't know how to fix it.

@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

From @usev6

On Wed Oct 01 13​:03​:29 2014, bartolin@​gmx.de wrote​:

my ($a is readonly) = 5; say $a; $a++; say $a;
5
6

I think the last one should also result in a compile time error. But I
don't know how to fix it.

AFAIU this doesn't die because '($a is readonly)' is parsed as a signature and is not checked as strictly as the assignments (see e.g. https://rt-archive.perl.org/perl6/Ticket/Display.html?id=74664#txn-686876).

So, we're back to 'things have changed and infix​:<​::=> is used instead of a variable trait "is readonly"'. To be sure that the right exception is thrown when someone uses the old "is readonly", I added two tests to S03-binding/ro.t with commit Raku/roast@8a07d59e32.

If I'm not mistaken, there is nothing else to do in this context. If that's not the case, please reopen the ticket.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

From @usev6

On Wed Oct 01 13​:03​:29 2014, bartolin@​gmx.de wrote​:

my ($a is readonly) = 5; say $a; $a++; say $a;
5
6

I think the last one should also result in a compile time error. But I
don't know how to fix it.

AFAIU this doesn't die because '($a is readonly)' is parsed as a signature and is not checked as strictly as the assignments (see e.g. https://rt-archive.perl.org/perl6/Ticket/Display.html?id=74664#txn-686876).

So, we're back to 'things have changed and infix​:<​::=> is used instead of a variable trait "is readonly"'. To be sure that the right exception is thrown when someone uses the old "is readonly", I added two tests to S03-binding/ro.t with commit Raku/roast@8a07d59e32.

If I'm not mistaken, there is nothing else to do in this context. If that's not the case, please reopen the ticket.

@p6rt
Copy link
Author

p6rt commented Oct 22, 2014

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant