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 shouldn't allow calling $obj.UnrelatedClass::method() on a non-ancestor class #1305

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

Comments

@p6rt
Copy link

p6rt commented Sep 21, 2009

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

Searchable as RT69262$

@p6rt
Copy link
Author

p6rt commented Sep 21, 2009

From @masak

<masak> rakudo​: class A { method foo() { say "A" } }; class B {}; my
$b = B.new; $b.A​::foo
<p6eval> rakudo 836c8c​: OUTPUT«A␤»
<masak> o.O
<masak> wait a minute.
<masak> the classes do not inherit from each other.
<jnthn> masak​: oh
<jnthn> masak​: In that case it'll try and explode.
<masak> I agree.
<masak> but that's actually two bugs, then.
<jnthn> well, it's the same underlying issue
* masak pretends not to hear that
<masak> two tickets coming up!

@p6rt
Copy link
Author

p6rt commented Sep 21, 2009

From @pmichaud

On Mon, Sep 21, 2009 at 06​:41​:37AM -0700, Carl Mäsak wrote​:

<masak> rakudo​: class A { method foo() { say "A" } }; class B {}; my
$b = B.new; $b.A​::foo
<p6eval> rakudo 836c8c​: OUTPUT«A␤»
<masak> o.O
<masak> wait a minute.
<masak> the classes do not inherit from each other.
<jnthn> masak​: oh
<jnthn> masak​: In that case it'll try and explode.
<masak> I agree.
<masak> but that's actually two bugs, then.
<jnthn> well, it's the same underlying issue
* masak pretends not to hear that
<masak> two tickets coming up!

I agree that the existing behavior is wrong, but what
should happen here? Should it report a type mismatch on
the invocant when invoking A​::foo, or should it complain
that A​::foo isn't a valid method for a B object?

Pm

@p6rt
Copy link
Author

p6rt commented Sep 21, 2009

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

@p6rt
Copy link
Author

p6rt commented Sep 26, 2009

From @moritz

On Mon Sep 21 12​:07​:15 2009, pmichaud wrote​:

I agree that the existing behavior is wrong, but what
should happen here? Should it report a type mismatch on
the invocant when invoking A​::foo, or should it complain
that A​::foo isn't a valid method for a B object?

I'd say the latter, because "type mismatch on the invocant" might be
mightily confusing.

Cheers,
Moritz

@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-class/inheritance.t

commit 395a0b0e02df40b34795fa94d1e9cdcdecc82369
Author​: moritz <moritz@​c213334d-75ef-0310-aa23-eaa082d1ae64>
Date​: Sat Sep 26 16​:23​:50 2009 +0000

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

Inline Patch
diff --git a/t/spec/S12-class/inheritance.t b/t/spec/S12-class/inheritance.t
index 4260be3..db6f263 100644
--- a/t/spec/S12-class/inheritance.t
+++ b/t/spec/S12-class/inheritance.t
@@ -2,7 +2,7 @@ use v6;
 
 use Test;
 
-plan 36;
+plan 38;
 
 # L<S12/Classes/An "isa" is just a trait that happens to be another class>
 
@@ -20,6 +20,10 @@ class Foo::Bar is Foo {
     method super_baz ($self:) { return $self.Foo::baz() }
 }
 
+class Unrelated {
+    method something { 'bad' };
+}
+
 my $foo_bar = Foo::Bar.new();
 isa_ok($foo_bar, Foo::Bar);
 
@@ -47,6 +51,11 @@ my $fud;
 lives_ok { $fud = $foo_bar.getme.fud }, 'chained method dispatch on altered method';
 is($fud, "Foo::Bar::fud", "returned value is correct");
 
+is $foo_bar.Foo::baz, 'Foo::baz', '$obj.Class::method syntax works';
+#?rakudo todo 'RT 69262'
+dies_ok { $foo_bar.Unrelated::something() },
+    'Cannot call unrelated method with $obj.Class::method syntax';
+
 # See thread "Quick OO .isa question" on p6l started by Ingo Blechschmidt:
 # L<"http://www.nntp.perl.org/group/perl.perl6.language/22220">
 

@p6rt
Copy link
Author

p6rt commented Mar 13, 2010

From @jnthn

On Sat Sep 26 09​:23​:06 2009, moritz wrote​:

On Mon Sep 21 12​:07​:15 2009, pmichaud wrote​:

I agree that the existing behavior is wrong, but what
should happen here? Should it report a type mismatch on
the invocant when invoking A​::foo, or should it complain
that A​::foo isn't a valid method for a B object?

I'd say the latter, because "type mismatch on the invocant" might be
mightily confusing.

Agree, done while putting back .A​::foo style syntax, and un-todo'd the
now passing test for this.

Thanks,

Jonathan

@p6rt
Copy link
Author

p6rt commented Mar 13, 2010

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

@p6rt p6rt closed this as completed Mar 13, 2010
@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