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

&substr exported from Cool.substr doesn't type check on its first argument in Rakudo #1914

Closed
p6rt opened this issue Jul 7, 2010 · 4 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Jul 7, 2010

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

Searchable as RT76412$

@p6rt
Copy link
Author

p6rt commented Jul 7, 2010

From @masak

<masak> rakudo​: Any.substr(0, 1)
<p6eval> rakudo ddf224​: OUTPUT«Method 'substr' not found for invocant
of class '' [...]
<masak> I think I read somewhere that this is expected nowadays.
<masak> and I think I agree.
<moritz_> right
<masak> rakudo​: substr(Any, 0, 1)
<p6eval> rakudo ddf224​: OUTPUT«Method 'chars' not found for invocant
of class ''␤ in 'Cool​::substr' at line 2121​:CORE.setting [...]
<masak> but that... why does it even call something?
* masak submits rakudobug
<pmichaud> maybe want a type constraint on the first arg.
<moritz_> it should type-constrain substr() to Cool
<masak> moritz_​: that's what I think too.
<pmichaud> (or invocant, if it's an "is export" method)
<masak> AFAICS, the sub is exported from Cool.substr
<masak> so it should have an implicit typing on the invocant.
<pmichaud> right

* * *
<TimToady> hmm, if substr calls chars, we can't use it to test a cat
string to see if there are more chars with $cat.substr($pos,1)
<masak> I'd actually like to ask for &substr the sub to work on Any,
if that's at all possible.
<TimToady> Any is not Cool
<moritz_> might be a pecularity of the implementation though
<masak> it could just coerce it to an empty Str or somthing.
<pmichaud> the use of .chars is undoubtedly a think-o.
<pmichaud> lots of times people contributing code run to .elems and
.chars without asking if there's a lazier way to do it
<moritz_> maybe it was to avoid "can't take substr out of range" or so
<TimToady> well, one way or another, we need a primitive that lets us
work through a string without committing to finding its end
<moritz_> ... and please don't let it be split() :-)
<pmichaud> my $len = $length // self.chars;
<pmichaud> bah.
<pmichaud> TimToady​: we're safe there, though -- if $length is
provided we don't call .chars
<pmichaud> (we break a little later on, but that's fixable)
* * *

<masak> I need to delimit this ticket somehow. I think the bug is that
the sub is not constrained to Cool.
<masak> but I'll include the other things too for posterity.
<moritz_> masak​: that's right
<TimToady> perhaps cat strings have "false ends", and there's just an
extra loop around when you think you've run out that increases it
<jnthn> Note that Rakudo doesn't put type constraints on invocants properly yet
<jnthn> So if the method is exported it won't type-check its invocant
unless you are explicit about what it should check just yet.
<jnthn> A few days ago, it didn't even do that though... :-)
<pmichaud> right

@p6rt
Copy link
Author

p6rt commented Jul 29, 2010

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

@p6rt
Copy link
Author

p6rt commented Oct 21, 2011

From @moritz

now fixed in nom, and tested in S32-str/substr.t.

@p6rt
Copy link
Author

p6rt commented Oct 21, 2011

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

@p6rt p6rt closed this as completed Oct 21, 2011
@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