Included diff.pl fails with a type check error
Closed this issue · 4 comments
Hi,
When trying the supplied diff.pl script (in order to quickly see how to module works), I get this type chck error:
$ bin/diff.pl t/auth1_less t/auth2_less
Type check failed in binding $high; expected Any but got Mu
in sub _replaceNextLargerWith at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:56
in block at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:191
in sub _longestCommonSubsequence at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:179
in sub _longestCommonSubsequence at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:150
in sub traverse_sequences at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:238
in sub diff at /home/claudio/.rakudobrew/moar-nom/install/share/perl6/site/sources/EFA9D27A73FB0C94F09CBE8AC3F44BE23F93E6A4:459
in sub MAIN at bin/diff.pl:29
in block at bin/diff.pl:15
Running on Ubuntu 15.10 64-bit:
$ uname -a
Linux melbourne 4.2.0-18-generic #22-Ubuntu SMP Fri Nov 6 18:25:50 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
$ perl6 -v
This is rakudo version 2015.11-435-gc27a00c built on MoarVM version 2015.11-34-gc3eea17 implementing Perl v6.b.
Thank you,
C.
This pretty much breaks the module for practical uses.
This can be fixed by simply typing $high as Mu in the definition of
_replaceNextLargerWith... Or... by using undefined Int or Nil for "undef".
The only advantage to Mu is it hard-fails if it explodes rather than just
warning. But Int would be best for users of _replaceNextLargerWith
since they might reasonably want to assign the result to an Int.
(assuming that sub is of any use to users)
In that case, $k in _longestCommonSubsequence needs to be typed
as Int. Also might want to change the Mu on line 204 to Int.
To reproduce:
need Algorithm::Diff;
my $a = "The Way that can be told of is not the eternal Way";
my $b = "The Tao that can be told of is not the eternal Tao";
my @alist = $a.split(/<|w>/);
my @blist = $b.split(/<|w>/);
my $diff = Algorithm::Diff.new(@alist, @blist);
Notice that when you change $b to end in "Way" instead of "Tao", the error disappears.
@skids Do you have a test case for your suggestions? I can confirm that return Int instead of Mu fixed my issue. Making the other two changes you suggested didn't break the tests but they also didn't seem to be necessary so I didn't include them. I'd be happy to make those additional changes, though.
The script has been renamed to diff.raku
. I cannot reproduce the issue.
Please re-open if you disagree.