Declare and use similar but different Types

I have these declaration:

type 
   TPoint2d = record
    x : Double;
	y : double;
   end;

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

 type 
  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…

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…

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;
 begin
  l := s;
 end;

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

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

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

should be different types.

so

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

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

1 Like

Ah yes, sry…

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

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

In Delphi, FreePascal, Oxygene

type
TypeA = TypeB

always creates an allias
However,

 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?

Regards

+1

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

example.zip (117.8 KB)

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.

1 Like

Thanks, logged as bugs://78523

That would be perfect.

1 Like

bugs://78523 got closed with status fixed.

fixed for v10.

Ok these should work now?

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

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

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

   end;

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