On Jul 18, 2008, at 5:18 PM, Jonathan Worthington wrote:
Hi,
Chris Fields wrote:
The PGE::Match appears to be converted to a Str, regardless of the
invoking object type. The following is .match (in any-str.pir,
with the builtins). Also, .ACCEPTS now uses .match to retrieve the
Match object.
# any-str.pir
.sub 'match' :method :multi(_)
.param pmc x
.local pmc match
match = x(self)
.return (match)
.end
# Code.pir
.sub 'ACCEPTS' :method
.param pmc topic
.local pmc match
match = topic.'match'(self)
$P0 = getinterp
$P1 = $P0['lexpad';1]
$P1['$/'] = match
.return (match)
.end
the following is a test p6 script (results in comments):
my $x = '123.456';
my $y = $x.match(/\d+/);
say $x; # 123.456
say $x.WHAT; # Str
say $y; # 123
say $y.WHAT; # Str <- Should be Match
Ouch! But I've tracked it down. :-) The interesting thing is that:
my $x = "foo"; say ($x.match(/o+/)).WHAT; # Match
So it fails in the assignment. And that's because infix:= to a
scalar does:
.sub 'infix:=' :method
.param pmc source
$P0 = source.'item'()
assign self, $P0
.return (self)
.end
And calling item on a Match object gets the string that matched.
Thus why we don't get the Match object. So, that's the cause; I'm
not sure what the correct fix is, so I'll delegate to pmichaud on
that one. We could special case it, but it doesn't feel very clean,
and special cases in a hot code patch like infix:= probably ain't so
desirable.
Thanks,
Jonathan
Good catch, jonathan++
I would rather wait for the right fix so no hurry (special casing
seems wrong to me as well). I'll start a ticket so it doesn't get
lost in the ether. We can implement .match after that, doesn't make
sense to have it pass back the wrong thing in the meantime.
chris