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

LTA error when sprintf %d directive doesn't find a corresponding argument in Rakudo #3542

Closed
p6rt opened this issue Oct 4, 2014 · 4 comments

Comments

@p6rt
Copy link

p6rt commented Oct 4, 2014

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

Searchable as RT122907$

@p6rt
Copy link
Author

p6rt commented Oct 4, 2014

From @masak

<TuxCM> m​: my@​x=("1ab");for @​x { s{^(\d+)} = sprintf "%3d​:", $1; }; @​x.say
<camelia> rakudo-moar 16232f​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<gtodd1> so you want to format the digit in the list?
<[TuxCM]> gtodd1, yes
<gtodd1> m​: my @​x=("1ab");for @​x { s{^(\d+)} = sprintf "%3d :", "$1"; }; @​x.say
<camelia> rakudo-moar ae11b5​: OUTPUT« 0 :ab␤»
<gtodd> TuxCM​: hmm so the ^(\d+) bit doesn't work ... with the RHS
the as expected?
<gtodd> m​: my @​x=("1ab");for @​x { s{^(\d+)} = sprintf "%3d :", $1; }; @​x.say
<camelia> rakudo-moar ae11b5​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<[TuxCM]> gtodd, why does the $1 have to be quoted???
<[TuxCM]> m​: my @​x=("1ab");for @​x { s{^(\d+)} = sprintf "%3d :", "$1"; }; @​x.say
<camelia> rakudo-moar 3af250​: OUTPUT« 0 :ab␤»
<[TuxCM]> m​: my @​x=("1ab");for @​x { s{^(\d+)} = sprintf "%3d :", $1; }; @​x.say
<camelia> rakudo-moar 3af250​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<[TuxCM]> THAT is what I was wondering about
<masak> m​: for my @​x = "1ab" { s{^(\d+)} = sprintf "%3d :", Nil }
<camelia> rakudo-moar 3af250​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<masak> m​: $_ = "1ab"; s{^(\d+)} = sprintf "%3d :", "$1"; .say
<camelia> rakudo-moar 3af250​: OUTPUT«use of uninitialized value of
type Any in string context [...]␤␤ 0 :ab␤»
<masak> m​: $_ = "1ab"; s{^(\d+)} = sprintf "%3d :", $1; .say
<camelia> rakudo-moar 3af250​: OUTPUT«No such method 'Int' for invocant
of type 'Any'␤␤»
<masak> oh!
<masak> $1 !
<masak> m​: $_ = "1ab"; s{^(\d+)} = sprintf "%3d :", $0; .say
<camelia> rakudo-moar 3af250​: OUTPUT« 1 :ab␤»
<masak> :)
<masak> I think the real bug is that sprintf reacts badly to a Nil.
<masak> m​: sprintf "%d", Nil
<camelia> rakudo-moar 3af250​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<masak> that's LTA.
* masak submits that
<masak> m​: sprintf "%s", Nil
<camelia> rakudo-moar 3af250​: OUTPUT«Too many directives​: found 1, but
no arguments after the format string␤␤»
<masak> oh...
<masak> right, so the problem isn't the Nil as such.
<masak> but rather that there's nothing to populate the %d with.
<masak> m​: sprintf "%d"
<camelia> rakudo-moar 3af250​: OUTPUT«No such method 'item' for
invocant of type 'NQPMu' [...]
<masak> should give the same error as
<masak> m​: sprintf "%s"
<camelia> rakudo-moar 3af250​: OUTPUT«Too many directives​: found 1, but
no arguments after the format string␤␤»

@p6rt
Copy link
Author

p6rt commented Jan 23, 2015

From @usev6

sprintf "%d" now gives the same error as sprintf "%s"​:

$ perl6 -e 'sprintf "%s"'
Too many directives​: found 1, but no arguments after the format string

$ perl6 -e 'sprintf "%d"'
Too many directives​: found 1, but no arguments after the format string

This was fixed with commit Raku/nqp@f2577cb116. I added a test to S32-str/sprintf.t with commit Raku/roast@8fc7d0289c

I'm closing this ticket now.

1 similar comment
@p6rt
Copy link
Author

p6rt commented Jan 23, 2015

From @usev6

sprintf "%d" now gives the same error as sprintf "%s"​:

$ perl6 -e 'sprintf "%s"'
Too many directives​: found 1, but no arguments after the format string

$ perl6 -e 'sprintf "%d"'
Too many directives​: found 1, but no arguments after the format string

This was fixed with commit Raku/nqp@f2577cb116. I added a test to S32-str/sprintf.t with commit Raku/roast@8fc7d0289c

I'm closing this ticket now.

@p6rt
Copy link
Author

p6rt commented Jan 23, 2015

@usev6 - Status changed from 'new' 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