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

Private methods in roles don't bind 'self' correctly in Rakudo #3304

Closed
p6rt opened this issue Jan 2, 2014 · 9 comments
Closed

Private methods in roles don't bind 'self' correctly in Rakudo #3304

p6rt opened this issue Jan 2, 2014 · 9 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jan 2, 2014

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

Searchable as RT120919$

@p6rt
Copy link
Author

p6rt commented Jan 2, 2014

From @masak

<skids> r​: role A { method pub { self!priv }; method !priv () {
"OHAI".say } }; class C does A { }; C.new.pub;
<camelia> rakudo-jvm a77214​: OUTPUT«Nominal type check failed for
parameter 'null'␤␤»
<camelia> ..rakudo-parrot a77214​: OUTPUT«Nominal type check failed for
parameter ''; expected $?CLASS but got C instead␤ in method priv at
/tmp/eL6iqOxDYJ​:1␤ in method pub at /tmp/eL6iqOxDYJ​:1␤ in block at
/tmp/eL6iqOxDYJ​:1␤␤»
<skids> r​: role A { method pub { self!priv }; method !priv ($self​:) {
"OHAI".say } }; class C does A { }; C.new.pub;
<camelia> rakudo-parrot a77214, rakudo-jvm a77214​: OUTPUT«OHAI␤»
<masak> skids​: that... looks like a bug to me. at first blush.
<masak> skids​: looks like 'self' isn't parameterized correctly in
private methods in roles.
<masak> r​: class A { method pub { self!priv }; method !priv { say "OH
HAI" } }; A.new.pub
<camelia> rakudo-parrot a77214, rakudo-jvm a77214​: OUTPUT«OH HAI␤»
<masak> skids​: do you know if that's already submitted?
<skids> masak​: I do not. I was removing old workarounds from a year +
ago and found it.
* masak submits rakudobug
<lue> masak​: wait, how is that a bug? Seems reasonable to me.
<masak> lue​: note, it works in my last eval.
<masak> lue​: but it doesn't work in skid's first.
<masak> lue​: the only difference is that in skid's case, pub and !priv
are in a role.
<lue> masak​: oh, I thought you were discussing skids' last eval.
nevermind then :) [somehow I also missed the $self​: in that eval]
<masak> the second has a $self​:
<masak> the first doesn't.
<masak> the fact that those two differ in their result is also suspect.
<skids> At least the $self is a better workaround now than using a
public method was.

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @usev6

This works on Moar but fails on Parrot and JVM​:

$ perl6-m -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
OH HAI

$ perl6-p -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
  in any type_check at gen/parrot/Metamodel.nqp​:297
  in block at gen/parrot/CORE.setting​:963
  in method BUILDALL at gen/parrot/CORE.setting​:946
  in method bless at gen/parrot/CORE.setting​:935
  in method new at gen/parrot/CORE.setting​:920
  in method new at gen/parrot/CORE.setting​:918
  in method priv at -e​:1
  in method pub at -e​:1
  in block <unit> at -e​:1

$ perl6-j -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
  in any type_check at gen/jvm/Metamodel.nqp​:297
  in block at gen/jvm/CORE.setting​:949
  in method BUILDALL at gen/jvm/CORE.setting​:932
  in method bless at gen/jvm/CORE.setting​:921
  in method new at gen/jvm/CORE.setting​:905
  in method priv at -e​:1
  in method pub at -e​:1
  in block <unit> at -e​:1

I added a test (skipped for Parrot and JVM) to S14-roles/basic.t with the following commit​: Raku/roast@8942c27ab2

1 similar comment
@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

From @usev6

This works on Moar but fails on Parrot and JVM​:

$ perl6-m -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
OH HAI

$ perl6-p -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
  in any type_check at gen/parrot/Metamodel.nqp​:297
  in block at gen/parrot/CORE.setting​:963
  in method BUILDALL at gen/parrot/CORE.setting​:946
  in method bless at gen/parrot/CORE.setting​:935
  in method new at gen/parrot/CORE.setting​:920
  in method new at gen/parrot/CORE.setting​:918
  in method priv at -e​:1
  in method pub at -e​:1
  in block <unit> at -e​:1

$ perl6-j -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
  in any type_check at gen/jvm/Metamodel.nqp​:297
  in block at gen/jvm/CORE.setting​:949
  in method BUILDALL at gen/jvm/CORE.setting​:932
  in method bless at gen/jvm/CORE.setting​:921
  in method new at gen/jvm/CORE.setting​:905
  in method priv at -e​:1
  in method pub at -e​:1
  in block <unit> at -e​:1

I added a test (skipped for Parrot and JVM) to S14-roles/basic.t with the following commit​: Raku/roast@8942c27ab2

@p6rt
Copy link
Author

p6rt commented Oct 17, 2014

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

@p6rt
Copy link
Author

p6rt commented Oct 21, 2014

From @lizmat

On 17 Oct 2014, at 14​:45, Christian Bartolomaeus via RT <bugs-comment@​bugs6.perl.org> wrote​:

This works on Moar but fails on Parrot and JVM​:

$ perl6-m -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
OH HAI

$ perl6-p -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
in any type_check at gen/parrot/Metamodel.nqp​:297
in block at gen/parrot/CORE.setting​:963
in method BUILDALL at gen/parrot/CORE.setting​:946
in method bless at gen/parrot/CORE.setting​:935
in method new at gen/parrot/CORE.setting​:920
in method new at gen/parrot/CORE.setting​:918
in method priv at -e​:1
in method pub at -e​:1
in block <unit> at -e​:1

$ perl6-j -e 'role A { method pub { self!priv }; method !priv () { say "OH HAI" } }; class C does A { }; C.new.pub;'
Cannot type check against type variable $?CLASS
in any type_check at gen/jvm/Metamodel.nqp​:297
in block at gen/jvm/CORE.setting​:949
in method BUILDALL at gen/jvm/CORE.setting​:932
in method bless at gen/jvm/CORE.setting​:921
in method new at gen/jvm/CORE.setting​:905
in method priv at -e​:1
in method pub at -e​:1
in block <unit> at -e​:1

I added a test (skipped for Parrot and JVM) to S14-roles/basic.t with the following commit​: Raku/roast@8942c27ab2

Related​: $ 6 'role R { method !m(@​a) { say "ok​: @​a[]" }; method x() { self!m((my %).values) } }; class C does R { }; C.x'
No such method 'item' for invocant of type '$?CLASS'
  in method message at src/gen/m-CORE.setting​:13330
  in method m at -e​:1
  in method x at -e​:1
  in block <unit> at -e​:1

This only seems to happen when passing something like .values of a hash.

@p6rt
Copy link
Author

p6rt commented Aug 9, 2015

From @skids

This is a reminder that, when this bug is fixed, there are
workarounds for it to remove in src/core/IO/Local.pm and
(possibly, PR still pending) in src/core/Temporal.pm

In the former look for commented out lines accessig self! things
and use them to replace the workaround code in those methods

In the latter, make the VALID-UNIT method private and adjust
the calls to it.

@p6rt
Copy link
Author

p6rt commented Nov 21, 2015

From @usev6

The test in S14-roles/basic.t passes now on JVM.

Also the code from lizmat++ does not die​:

$ perl6 -e 'role R { method !m(@​a) { say "ok​: @​a[]" }; method x() { self!m((my %).values) } }; class C does R { }; C.x'
ok​:

I haven't yet looked at src/core/IO/Local.pm or src/core/Temporal.pm

1 similar comment
@p6rt
Copy link
Author

p6rt commented Nov 21, 2015

From @usev6

The test in S14-roles/basic.t passes now on JVM.

Also the code from lizmat++ does not die​:

$ perl6 -e 'role R { method !m(@​a) { say "ok​: @​a[]" }; method x() { self!m((my %).values) } }; class C does R { }; C.x'
ok​:

I haven't yet looked at src/core/IO/Local.pm or src/core/Temporal.pm

@p6rt p6rt closed this as completed Apr 7, 2016
@p6rt
Copy link
Author

p6rt commented Apr 7, 2016

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

@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