Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Overloading Effect
Thu, Dec 20 2018 9:35 AMPermanent Link

Michael Dreher

The code and compiler error message:

// 1)
function IFF(b : boolean; b1, b2 : boolean) : boolean;
begin
 if b then Result := b1 else Result := b2;
end;

// 2)
function IFF(b : boolean; i1, i2 : integer) : integer;
begin
 if b then Result := i1 else Result := i2;
end;

procedure Foo;
var
 i : integer;
 b : boolean;
begin          
 b := IFF(true, true, false);
 i := IFF(true, 2, 3);  // 3)
   //[Error] Unit1.wbs (38,8): Expected integer, variant,
   // or enumeration but instead found IFF(true, 2, 3)
end;

I have no idea what's wrong with 3). Because of the overloaded
function 2) it should be valid.

Michael Dreher
Thu, Dec 20 2018 10:38 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<< I have no idea what's wrong with 3). Because of the overloaded function 2) it should be valid. >>

Yeah, it's probably just the compiler getting confused, although it may be due to a "Boolean is type compatible with Integer" assumption in the compiler.

I'll check it out and let you know what I find out.

Tim Young
Elevate Software
www.elevatesoft.com
Thu, Dec 27 2018 11:31 AMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

Yeah, I looked into this and it's an issue with the fact that the compiler considers an Integer to be type-compatible with a Boolean.  So, I'm not sure what I'm going to do about this yet, but I'm going to need to put off any fixes for now until I can figure out a design that doesn't introduce any breakages.  It will probably need to revolve around a number of "mini-passes" over the function/procedure prototypes to see which has the *best* fit, as opposed to *a fit*.  Unfortunately, the compiler isn't designed to handle that form of type-checking at this time.

Tim Young
Elevate Software
www.elevatesoft.com
Wed, Jan 2 2019 7:10 AMPermanent Link

Michael Dreher

I found out that exchanging the order of the definitions 1) and 2) solves the issure
for this case. That's all I need. Thank You.

Michael Dreher
Image