Declare and use similar but different Types

(Friedrich Westermann) #1

I have these declaration:

   TPoint2d = record
    x : Double;
	y : double;

  TLine2d = array[0..1] of TPoint2d;

  TSegment2d = array[0..1] of TPoint2d;

  method Orientation(const Line:TLine2D; const Point:TPoint2D):Integer;                                                  
  method Orientation(const Segment:TSegment2D; const Point:TPoint2D):Integer;       

How to tell the compiler that these are different Types?
I got error on compile because of duplicate Type?
But the types are declared as different…

(shpend hoti) #2

I dont know if Oxygene provides something special about this, but the thing is, whats different is just the name, but the content is the same and the compiler is telling you exactly this, in the form of: in Both aliases you have the exact same array!.

And btw:

you just need 1 type for the types you declare under the word type!

And just Change the name maybe to: OrientByLines and OrientBySegment or something like this…

(Friedrich Westermann) #3

They are different Types;
They must be handelt as different;
They have a different meaning and pascal is a very type safe Language;

They should not even be assignment compatible.

In Delphi and FPC these will not compile:

procedure Test;
 Var L : TLine2d;
     s : TSegment2d;
  l := s;

(marc hoffman) #4

Sounds like a bug, can you send me a full test case? whats the platform?

(Friedrich Westermann) #5

The problem is simple. Platform is Toffee, not tried on other

TLine2d = array[0…1] of TPoint2d;
TSegment2d = array[0…1] of TPoint2d;

should be different types.


    procedure Test;
     Var L : TLine2d;
         s : TSegment2d;
      l := s;

must fail, because of it. That is what i expect from a strong Typed Language

(shpend hoti) #6

Ah yes, sry…

Ofc they must be different^^, my pleasure… Forgot a little bit the Type-Safeness

(marc hoffman) #7

I believe that’s designed, as both are aliases to the same array type.

(joseasl) #8

In Delphi, FreePascal, Oxygene

TypeA = TypeB

always creates an allias

 TArrayType = Array[0..1] of X;
 TArrayType2 = Array[0..1] of X;

are different types in Delphi, FreePascal, but not in Oxygene.
I prefer the consistency of Oxygene, TypeA = TypeB is always an alias but
we should be able to use

TypeA = type TypeB

as in Delphi, FreePascal, if we want the types to be different.
And then we should be able to do TArrayType = type Array[0…1] of X;

What do you think?


(Kazantsev Alexey) #9


(Friedrich Westermann) #10

Yes i think we need these option.
The difference to all other Pascal compiler’s is to “big” if you are working with legacy code (117.8 KB)

(marc hoffman) #11

Agreed. we should add support for type, but the array syntax should stay behaving as it is (an alias), and also require/support type to make them distinct.

(RemObjects) #12

Thanks, logged as bugs://78523

(joseasl) #13

That would be perfect.

(RemObjects) #14

bugs://78523 got closed with status fixed.

(marc hoffman) #15

fixed for v10.

(Friedrich Westermann) #16

Ok these should work now?

TDoubleArray = array[1..2] of Double;
TdoubleArray2 = type TDoubleArray;

   test = class
   method Test(Values : TDoubleArray);
     if Values[1] <> Values[2] then;

  method Test2(Values : TDoubleArray2);
     if Values[1] <> Values[2] then;


I get:

Severity Code Description Project File Line Suppression State
Error (E189) Type “TdoubleArray2” has no default property to use for array accessors X:\Elements\Tests\Codefile1.pas 17