On 2020-05-27 14:32, Andy Bach wrote:
#!/usr/bin/env raku
my Str $x;
if $x.starts-with( "[" )  &&
$x.contains( "]" )
{ say "Passed"; } else { say "Failed"; }

K:\Windows\NtUtil>raku Contains.Test.pl6
Cannot resolve caller starts-with(Str:U: Str:D); none of these
signatures match

(Cool:D: Cool:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_
--> Bool)
(Cool:D: Cool:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Cool:D: Cool:D $needle, *%_ --> Bool)
(Str:D: Str:D $needle, :i(:$ignorecase)!, :m(:$ignoremark), *%_ -->
Bool)
(Str:D: Str:D $needle, :m(:$ignoremark)!, *%_ --> Bool)
(Str:D: Str:D $needle, *%_ --> Bool)
in block <unit> at Contains.Test.pl6 line 3

 > The function should just complain that the variable is not initialized.



Well, it is:
Cannot resolve caller starts-with(Str:U: Str:D);
...
in block <unit> at Contains.Test.pl6 line 3

it says:
For line 3:
if $x.starts-with( "[" )
looking for a possible method 'starts-with' with a signature of 2 params; an undefined string ('Str:U:') and a defined one ('Str:D:') failed - here's the list of the possible signatures raku currently has ..."

I'd not be surprise if you could write your own "starts-with(Str:U: Str:D); " method in raku and take care of this.  You could probably even have it "say" You have an undefined String var in this call, not going to be able to do much useful matching against that.  Did you forget to initialize something?

Hi Andy,

The function should just complain that you need to feed it an
initialized value instead of sending you on a wild goose chase,

In that snippet, I deliberately did not initialize the variable
to trigger the weird behavior.

When I first encountered this error, I was testing a similar
uninitialized variable. I thought it was populated because "say" said so. "say" just had some shadow of another variable I had used to populate the uninitialized variable.

The value looked correct.  I spend a lot of time chasing
the wrong rabbit down the wrong rabbit hole.

-T

Reply via email to