petdance/scratch — Issue #957: subclassing basic number types fails to inherit basic ops like add, sub, mul and div
Author: petdance
Created: 2011-11-01 05:38:38+00:00
State: open
Labels: bug, core, Pri-critical, Sev-high

When subclassing base types like Integer, Float and Complex. The ops sub, add, mul and div are not properly inherited by the derived class.
A basic example is provided by the following code: -

{{{
.sub '' :main
$P0 = subclass 'Integer', 'FooInt'

print 'Integer: 10 - 1 = '
$P0 = new 'Integer'
$P0 = 10
sub $P1, $P0, 1
say $P1

print 'FooInt: 10 - 1 = '
$P0 = new 'FooInt'
$P0 = 10
#$P1 = new 'FooInt' # uncommenting here does not help
sub $P1, $P0, 1
say $P1
.end
}}}

outputs the following: -

{{{
Integer: 10 - 1 = 9
FooInt: 10 - 1 = Multiple Dispatch: No suitable candidate found for 'subtract_int', with signature 'PIP->P'
...
}}}

This appears to be related to RT http://rt.perl.org/rt3/Public/Bug/Display.html?id=59630 which outlines the problem for a specific case of a Complex type.

The attached script proves the bug also affects add, sub, mul, div for Integer, Float and Complex. It could be used as a test case.

Originally http://trac.parrot.org/parrot/ticket/562