Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Useless use of "-" in expression "-1" in sink context (line 13)

Tags:

raku

I'm trying to make tests for a function that throws an exception with this code:

use v6;
use Test;

plan *;

use lib "lib";
use Math::ConvergenceMethods;

sub f ($x) {return $x + 1;}


{
    is-approx: bisection(&f, -2, 0), -1;
    dies-ok: { bisection(&f, 3, 2) }, "Incorrect arguments";
}

done-testing;

And it returns this warnings when I run it:

WARNINGS for /home/antonio/Code/perl6/Math-ConvergenceMethods/t/bisection.t:
Useless use of "-" in expression "-1" in sink context (line 13)
Useless use of constant string "Incorrect arguments" in sink context (lines 14, 14)

How can I fix it?

like image 572
Antonio Gamiz Delgado Avatar asked Mar 14 '19 11:03

Antonio Gamiz Delgado


1 Answers

The foo in a statement of the form:

foo: ...

is a label where the ... is the statement that it labels.

So the statement you've written is the same as:

bisection(&f, -2, 0), -1;

which leaves the -1 in sink context, hence the error message.

(The message is somewhat LTA because your mistake is clearly that you thought the label syntax was a function calling syntax and while the error message does indicate the error -- in sink context -- the Useless use of "-" is additional detail that doesn't help and probably added to your confusion.)

See also What's the difference these two function calling conventions?.

like image 63
raiph Avatar answered Oct 12 '22 16:10

raiph