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

Can't assign to int private attribute using signature #5674

Open
p6rt opened this issue Sep 15, 2016 · 8 comments
Open

Can't assign to int private attribute using signature #5674

p6rt opened this issue Sep 15, 2016 · 8 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Sep 15, 2016

Migrated from rt.perl.org#129278 (status was 'open')

Searchable as RT129278$

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

From @zoffixznet

#Doesn't work​:
<TestNinja> m​: class { has int $!n = 0; method x ($!n) {} }.new.x​: 42
<camelia> rakudo-moar 2c95f7​: OUTPUT«Cannot modify an immutable int␤ in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

# But does, if we use a temp var​:
<TestNinja> m​: class { has int $!n = 0; method x ($n) {$!n = $n} }.new.x​: 42
<camelia> rakudo-moar 2c95f7​: ( no output )

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

From @lizmat

This is a known issue, as there is no native support for attribute binding this way. There’s quite some code in the setting working around this issue :-(

On 15 Sep 2016, at 20​:49, Zoffix Znet (via RT) <perl6-bugs-followup@​perl.org> wrote​:

# New Ticket Created by Zoffix Znet
# Please include the string​: [perl #​129278]
# in the subject line of all future correspondence about this issue.
# <URL​: https://rt-archive.perl.org/perl6/Ticket/Display.html?id=129278 >

#Doesn't work​:
<TestNinja> m​: class { has int $!n = 0; method x ($!n) {} }.new.x​: 42
<camelia> rakudo-moar 2c95f7​: OUTPUT«Cannot modify an immutable int␤ in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

# But does, if we use a temp var​:
<TestNinja> m​: class { has int $!n = 0; method x ($n) {$!n = $n} }.new.x​: 42
<camelia> rakudo-moar 2c95f7​: ( no output )

@p6rt
Copy link
Author

p6rt commented Sep 15, 2016

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

@p6rt
Copy link
Author

p6rt commented Sep 21, 2016

From @jnthn

On Thu Sep 15 11​:49​:35 2016, cpan@​zoffix.com wrote​:

#Doesn't work​:
<TestNinja> m​: class { has int $!n = 0; method x ($!n) {} }.new.x​: 42
<camelia> rakudo-moar 2c95f7​: OUTPUT«Cannot modify an immutable int␤
in method x at <tmp> line 1␤ in block <unit> at <tmp> line 1␤␤»

I've fixed this and added tests to S12-methods/attribute-params.t. It works for named parameters too. So in terms of the originally reported issue this ticket could be considered done.

But.

Unfortunately, the moment you have a role instead of a class, or a a more complex signature (for example, involving an unpack), it fails. So, some more work and tests needed.

@p6rt
Copy link
Author

p6rt commented Oct 15, 2016

From @usev6

For the records​: This fails on JVM (has to be fixed in src/vm/jvm/runtime/org/perl6/rakudo/Binder.java, probabaly)​:

$ ./perl6-j -e 'class { has int $!n = 0; method x ($!n) {} }.new.x​: 42'
org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException​: Cannot access a native attribute as a reference attribute
  in method x at -e line 1
  in block <unit> at -e line 1

Tests that use the new method SeqNextNFromIterator fail due to this problem. From S32-list/head.t​:

$ ./perl6-j -e 'my $list = <a b b c>; say $list.head(3)'
org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException​: Cannot access a native attribute as a reference attribute
  in block <unit> at -e line 1

This works, if one doesn't use a native here​: https://github.com/rakudo/rakudo/blob/2c681c55520d34750663cdec2fefcf3005ee550e/src/core/Rakudo/Internals.pm#L266

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 15, 2016

From @usev6

For the records​: This fails on JVM (has to be fixed in src/vm/jvm/runtime/org/perl6/rakudo/Binder.java, probabaly)​:

$ ./perl6-j -e 'class { has int $!n = 0; method x ($!n) {} }.new.x​: 42'
org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException​: Cannot access a native attribute as a reference attribute
  in method x at -e line 1
  in block <unit> at -e line 1

Tests that use the new method SeqNextNFromIterator fail due to this problem. From S32-list/head.t​:

$ ./perl6-j -e 'my $list = <a b b c>; say $list.head(3)'
org.perl6.nqp.sixmodel.reprs.P6OpaqueBaseInstance$BadReferenceRuntimeException​: Cannot access a native attribute as a reference attribute
  in block <unit> at -e line 1

This works, if one doesn't use a native here​: https://github.com/rakudo/rakudo/blob/2c681c55520d34750663cdec2fefcf3005ee550e/src/core/Rakudo/Internals.pm#L266

@p6rt
Copy link
Author

p6rt commented Oct 18, 2016

From @usev6

On Sat Oct 15 00​:31​:09 2016, bartolin@​gmx.de wrote​:

[...]
Tests that use the new method SeqNextNFromIterator fail due to this
problem. From S32-list/head.t​:

Again, for the records​: lizmat++ put in a bandaid for rakudo-j with Rakudo commit 666128fc6e. The tests from S32-list/head.t run fine, but the underlying problem is still there.

@p6rt
Copy link
Author

p6rt commented Nov 23, 2016

From @usev6

On Tue, 18 Oct 2016 08​:39​:21 -0700, bartolin@​gmx.de wrote​:

Again, for the records​: lizmat++ put in a bandaid for rakudo-j with
Rakudo commit 666128fc6e. The tests from S32-list/head.t run fine, but
the underlying problem is still there.

The bandaid was remove recently (Rakudo commit e8f938b0f6) after psch++ implemented attribute parameter binding on the JVM.

So we are back to what jnthn said about roles or more complex signatures​:

On Wed, 21 Sep 2016 06​:30​:00 -0700, jnthn@​jnthn.net wrote​:

I've fixed this and added tests to S12-methods/attribute-params.t. It
works for named parameters too. So in terms of the originally reported
issue this ticket could be considered done.

But.

Unfortunately, the moment you have a role instead of a class, or a a
more complex signature (for example, involving an unpack), it fails.
So, some more work and tests needed.

@p6rt p6rt added the Bug label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant