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

Rakudo breaks encapsulation when calling a method from another class #1304

Closed
p6rt opened this issue Sep 21, 2009 · 7 comments
Closed

Rakudo breaks encapsulation when calling a method from another class #1304

p6rt opened this issue Sep 21, 2009 · 7 comments

Comments

@p6rt
Copy link

p6rt commented Sep 21, 2009

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

Searchable as RT69260$

@p6rt
Copy link
Author

p6rt commented Sep 21, 2009

From @masak

<masak> rakudo​: class A { has $!x; method foo() { say $!x } }; class B
{ has $!x = 42; }; my $b = B.new; $b.A​::foo
<p6eval> rakudo 836c8c​: OUTPUT«42␤»
<masak> bye-bye, encapsulation.
<jnthn> masak​: huh? You called a publicly visible method
<moritz_> outch
<jnthn> masak​: How does it break encapsulation?
<masak> jnthn​: I managed to use the A class to print a private
attribute of a B object. that's encapsulation breakage in my book.
<jnthn> masak​: oh, wait, I see what you mean
<jnthn> masak​: erm
<masak> thought so. :)
<jnthn> masak​: rakudo bug.
* masak submits
<jnthn> masak​: It should'a given you the $!x from A.
<masak> aye.

@p6rt
Copy link
Author

p6rt commented Sep 26, 2009

From @kyleha

This is an automatically generated mail to inform you that tests are now available in t/spec/S12-attributes/inheritance.t

commit f66cda4035ab6680f222c1f32b724786b40832b8
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sat Sep 26 16​:33​:20 2009 +0000

  [t/spec] tests for RT #​69260, private attributes leaking to parent class
 
  git-svn-id​: http://svn.pugscode.org/pugs@&#8203;28420 c213334d-75ef-0310-aa23-eaa082d1ae64

Inline Patch
diff --git a/t/spec/S12-attributes/inheritance.t b/t/spec/S12-attributes/inheritance.t
index da9eadc..17531e9 100644
--- a/t/spec/S12-attributes/inheritance.t
+++ b/t/spec/S12-attributes/inheritance.t
@@ -1,6 +1,6 @@
 use v6;
 use Test;
-plan 3;
+plan 5;
 
 # test relation between attributes and inheritance
 
@@ -25,4 +25,20 @@ class Artie61500 {
 eval_dies_ok 'class Artay61500 is Artie61500 { method bomb { return $!p } }',
     'Compile error for subclass to access private attribute of parent';
 
+class Parent {
+    has $!priv = 23;
+    method get { $!priv };
+}
+
+class Child is Parent {
+    has $!priv = 42;
+}
+
+#?rakudo 2 todo 'RT 69260'
+is Child.new().Parent::get(), 23,
+   'private attributes do not leak from child to parent class (1)';
+
+is Child.new().get(), 23,
+   'private attributes do not leak from child to parent class (2)';
+
 # vim: ft=perl6

@p6rt
Copy link
Author

p6rt commented Sep 26, 2009

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

@p6rt
Copy link
Author

p6rt commented Jul 31, 2010

From @masak

<masak> star​: class A { method foo {} }; class B { method foo { say "OH HAI" } }; my $b-foo =
B.^can("foo"); A.new.$b-foo()
<p6eval> star 2010.07​: OUTPUT«OH HAI␤»
<masak> \o/
<masak> discuss. :P
<TiMBuS> my mind!
<gfldex> masak​: That indeed works but it ain't very dwimmy.
<masak> gfldex​: I wonder what happens if I try to extract secrets that way.
<gfldex> I'm not sure if dwimmy and secrets are supposed to mix. :)
<masak> star​: class A { has $!x; method foo {} }; class B { has $!x; method foo { say $!x } }; my
$b-foo = B.^can("foo"); A.new(​:x(42)).$b-foo()
<p6eval> star 2010.07​: OUTPUT«42␤»
<masak> now, that's an encapsulation problem.
<masak> not sure at all how to solve that one.
* masak submits a hesitant rakudobug

@p6rt
Copy link
Author

p6rt commented Sep 29, 2011

From @jnthn

On Mon Sep 21 06​:38​:21 2009, masak wrote​:

<masak> rakudo​: class A { has $!x; method foo() { say $!x } }; class B
{ has $!x = 42; }; my $b = B.new; $b.A​::foo
<p6eval> rakudo 836c8c​: OUTPUT«42␤»
<masak> bye-bye, encapsulation.
<jnthn> masak​: huh? You called a publicly visible method
<moritz_> outch
<jnthn> masak​: How does it break encapsulation?
<masak> jnthn​: I managed to use the A class to print a private
attribute of a B object. that's encapsulation breakage in my book.
<jnthn> masak​: oh, wait, I see what you mean
<jnthn> masak​: erm
<masak> thought so. :)
<jnthn> masak​: rakudo bug.
* masak submits

Now​:

class A { has $!x; method foo() { say $!x } }; class B { has $!x = 42;
}; my $b = B.new; $b.A​::foo
Cannot dispatch to a method on A because it is not inherited or done by B

Probably worth a test to make sure it dies rather than does what it used to.

/jnthn

@p6rt
Copy link
Author

p6rt commented Jan 6, 2012

From @moritz

This is already tested in S12-class/inheritance.t​:

dies_ok { $foo_bar.Unrelated​::something() },
  'Cannot call unrelated method with $obj.Class​::method syntax';

@p6rt
Copy link
Author

p6rt commented Jan 6, 2012

@moritz - 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