Skip to content

Commit

Permalink
Deprecate dummy arg on .Rat/.FatRat…
Browse files Browse the repository at this point in the history
For Rat, FatRat, and Int types
  • Loading branch information
zoffixznet committed Sep 27, 2017
1 parent 167f0f8 commit 4c337e8
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
14 changes: 10 additions & 4 deletions src/core/Int.pm
Expand Up @@ -48,11 +48,17 @@ my class Int does Real { # declared in BOOTSTRAP
nqp::p6box_n(nqp::tonum_I(self));
}

method Rat(Int:D: $?) {
Rat.new(self, 1);
proto method Rat(|) {*}
multi method Rat(Int:D:) { Rat.new(self, 1) }
multi method Rat(Int:D: $) {
DEPRECATED :lang-vers, '.Rat coercer without an argument', '6.d', '6.e';
self.Rat
}
method FatRat(Int:D: $?) {
FatRat.new(self, 1);
proto method FatRat(|) {*}
multi method FatRat(Int:D:) { FatRat.new(self, 1) }
multi method FatRat(Int:D: $) {
DEPRECATED :lang-vers, '.FatRat coercer without an argument', '6.d', '6.e';
self.FatRat
}

method abs(Int:D:) {
Expand Down
32 changes: 28 additions & 4 deletions src/core/Rat.pm
@@ -1,7 +1,19 @@
# XXX: should be Rational[Int, UInt64]
my class Rat is Cool does Rational[Int, Int] {
method Rat (Rat:D: Real $?) { self }
method FatRat(Rat:D: Real $?) { FatRat.new($!numerator, $!denominator); }
proto method Rat(|) {*}
multi method Rat(Rat:D: ) { self }
multi method Rat(Rat:D: Real) {
DEPRECATED :lang-vers, '.Rat coercer without an argument', '6.d', '6.e';
self
}

proto method FatRat(|) {*}
multi method FatRat(Rat:D:) { FatRat.new($!numerator, $!denominator); }
multi method FatRat(Rat:D: Real) {
DEPRECATED :lang-vers, '.FatRat coercer without an argument', '6.d', '6.e';
self.FatRat
}

multi method perl(Rat:D:) {
if $!denominator == 1 {
$!numerator ~ '.0'
Expand All @@ -24,12 +36,24 @@ my class Rat is Cool does Rational[Int, Int] {
}

my class FatRat is Cool does Rational[Int, Int] {
method FatRat(FatRat:D: Real $?) { self }
method Rat (FatRat:D: Real $?) {
proto method FatRat(|) {*}
multi method FatRat(FatRat:D:) { self }
multi method FatRat(FatRat:D: Real) {
DEPRECATED :lang-vers, '.FatRat coercer without an argument', '6.d', '6.e';
self
}

proto method Rat(|) {*}
multi method Rat(FatRat:D:) {
$!denominator < $UINT64_UPPER
?? Rat.new($!numerator, $!denominator)
!! Failure.new("Cannot convert from FatRat to Rat because denominator is too big")
}
multi method Rat (FatRat:D: Real) {
DEPRECATED :lang-vers, '.Rat coercer without an argument', '6.d', '6.e';
self.Rat
}

multi method perl(FatRat:D:) {
"FatRat.new($!numerator, $!denominator)";
}
Expand Down
36 changes: 36 additions & 0 deletions t/02-rakudo/v6.d-tests/01-deprecations.t
@@ -0,0 +1,36 @@
use lib <t/spec/packages/>;
use Test;
use Test::Util;

plan 8;

# XXX TODO: swap v6.d.PREVIEW to v6.d, once the latter is available
constant $v6d = 'v6.d.PREVIEW';

################### HELPER ROUTINES ###################################

sub test-deprecation (
Str:D $lang, Str:D $code, Str:D $desc = "with `$code`",
Bool :$is-visible
) {
is_run '
use \qq[$lang];
%*ENV<RAKUDO_NO_DEPRECATIONS>:delete;
\qq[$code]
', { :out(''), :err($is-visible ?? /deprecated/ !! ''), :0status },
($is-visible ?? 'shows' !! 'no ')
~ " deprecation message $desc [using $lang]";
}
sub is-deprecated (|c) { test-deprecation |c, :is-visible }
sub isn't-deprecated (|c) { test-deprecation |c }
sub is-newly-deprecated (|c) {
is-deprecated $v6d, |c;
isn't-deprecated 'v6.c', |c;
}

######################################################################

is-newly-deprecated $ = 4.2.Rat: 42;
is-newly-deprecated $ = 4.2.FatRat: 42;
is-newly-deprecated $ = FatRat.new(4,2).Rat: 42;
is-newly-deprecated $ = FatRat.new(4,2).FatRat: 42;

0 comments on commit 4c337e8

Please sign in to comment.