# New Ticket Created by  "Carl Mäsak" 
# Please include the string:  [perl #65308]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=65308 >


<masak> rakudo: subset FooStr of Str where /^foo/; multi method
trim(FooStr $self:) { return "OH HAI" }; say "foo".trim
<p6eval> rakudo b83a0b: OUTPUT«OH HAI␤»
<masak> that's just... so cool.
<masak> I can haz dispatch on subtyped invocant! \o/
<masak> rakudo: subset FooStr of Str where /^foo/; multi method
trim(FooStr $self:) { return "OH HAI" }; say "bar".trim
<p6eval> rakudo b83a0b: OUTPUT«No applicable candidates found to
dispatch to for 'trim'␤current instr.: 'parrot;P6metaclass;dispatch'
pc 243371 (src/gen_actions.pir:0)␤»
<masak> jnthn: how come that doesn't work, though?
<masak> it seems an applicable candidate to me...
<jnthn> You're deifning methods outside of a class...
<masak> jnthn: anyway... why doesn't the "bar" version dispatch to Str.trim?
<masak> more importantly, is it something I should tell RT about?
<jnthn> masak: I'm not entirely sure how/why the first one works.
<masak> :)
<masak> it felt amazing that it did, to be sure.
<masak> I mean, who needs monkeypatching when you can dispatch on
subtyped invocants?
<jnthn> Well, you're essentially monkey-patching without the monkey.
<masak> *lol*
<jnthn> masak: On subset decl issue, already there is 64098[BUG] MMD
on subset types fails for short name
<masak> oh, ok.
<masak> not the same issue, I'd say.
<masak> problem is, I don't really know what the issue should be with
the monkey-sans-monkey-patching.
<masak> is it that the original method is hidden?
<masak> or that dispatching on subset types of the invocant shouldn't
be allowed at all?
<jnthn> I don't know that writing a method outside a class like that
is allowed (other than having heard various references to some Main
class...)
<jnthn> (and either way, Main is not Any)
<jnthn> My guess is that you're ending up augmenting the exported trim
<masak> is there a place in the spec that mentions declaring methods
outside of their class scope?
<jnthn> And we didn't clone the multi that the class exported, and
thus why it looked like it affectd the class.
<jnthn> Anonlymous ones yes, named ones I can't recall one.
<jnthn> But there are I think references to a class Main.
<masak> jnthn: should I report it as a bug saying that the Str.trim
should still work?
<jnthn> There's *something* wrong that your example reveals.
<jnthn> I'm not completely sure what it is yet.
<masak> me neither.
<jnthn> I'm pretty sure that you should not have been able to affect
the Str class though.
<jnthn> We might be missing some cloning in the exporter.
* masak hesitantly submits a rakudobug
<jnthn> Well, I mean that a method with a Str invocant declared out of
class Str or not monkey-patched into it should not affect instances of
Str.
<jnthn> I think that might be the real wtf here.
<masak> jnthn: aye.
<masak> feels like monkey-patching from the outside.

Reply via email to