I don't know if it is a bug (yes of course it is a bug) or maybe a feature to have helpers for generic types through a backdoor.
I don't know if it is a bug (yes of course it is a bug) or maybe a feature to have helpers for generic types through a backdoor.
Given:
unit Unit1;
interface
type
Foo = record
Value: T;
end;
type
FooInteger = Foo;
HelperForFooInteger = record helper for FooInteger
function Multiply( const AValue: Integer ): Integer;
end;
type
FooSingle = Foo;
HelperForFooSingle = record helper for FooSingle
function Multiply( const AValue: Single ): Single;
end;
implementation
{ HelperForFooInteger }
function HelperForFooInteger.Multiply( const AValue: Integer ): Integer;
begin
WriteLn( 'HelperForFooInteger.Multiply' );
Result := Self.Value * AValue;
end;
{ HelperForFooSingle }
function HelperForFooSingle.Multiply( const AValue: Single ): Single;
begin
WriteLn( 'HelperForFooSingle.Multiply' );
Result := Self.Value * AValue;
end;
end.
What do you expect from this code?
var
fooInt : Foo;
begin
fooInt.Value := 5;
WriteLn( fooInt.Multiply( 10 ) );
end;
No, you are wrong ... you will get
HelperForFooSingle.Multiply
7.00649232162409E-0044
https://quality.embarcadero.com/browse/RSP-13574
https://quality.embarcadero.com/browse/RSP-13574
Given:
unit Unit1;
interface
type
Foo
Value: T;
end;
type
FooInteger = Foo
HelperForFooInteger = record helper for FooInteger
function Multiply( const AValue: Integer ): Integer;
end;
type
FooSingle = Foo
HelperForFooSingle = record helper for FooSingle
function Multiply( const AValue: Single ): Single;
end;
implementation
{ HelperForFooInteger }
function HelperForFooInteger.Multiply( const AValue: Integer ): Integer;
begin
WriteLn( 'HelperForFooInteger.Multiply' );
Result := Self.Value * AValue;
end;
{ HelperForFooSingle }
function HelperForFooSingle.Multiply( const AValue: Single ): Single;
begin
WriteLn( 'HelperForFooSingle.Multiply' );
Result := Self.Value * AValue;
end;
end.
What do you expect from this code?
var
fooInt : Foo
begin
fooInt.Value := 5;
WriteLn( fooInt.Multiply( 10 ) );
end;
No, you are wrong ... you will get
HelperForFooSingle.Multiply
7.00649232162409E-0044
https://quality.embarcadero.com/browse/RSP-13574
https://quality.embarcadero.com/browse/RSP-13574
Well a backdoor that leads into the dumpster as it does not work which I call a bug and not a backdoor. It would be a backdoor if it accidentally would work.
ReplyDelete/bug.sub
ReplyDelete