why two aliases to “array of string” treated differently?

The key to understanding this issue is the Type Compatibility and Identity topic in the language guide. I suggest you have a good read of that topic.

It is also helpful to simplify the example. The inclusion of generics in the example serves mainly to complicate and confuse matters.

program TypeCompatibilityAndIdentity;
{$APPTYPE CONSOLE}

type
  TInteger1 = Integer;
  TInteger2 = Integer;
  TArray1 = array of Integer;
  TArray2 = array of Integer;
  TArray3 = TArray1;

var
  Integer1: TInteger1;
  Integer2: TInteger2;
  Array1: TArray1;
  Array2: TArray2;
  Array3: TArray3;

begin
  Integer1 := Integer2; // no error here
  Array1 := Array2; // E2010 Incompatible types: 'TArray1' and 'TArray2'
  Array1 := Array3; // no error here
end.

From the documentation:

When one type identifier is declared using another type identifier, without qualification, they denote the same type.

This means that TInteger1 and TInteger2 are the same type, and are indeed the same type as Integer.

A little further on in the documentation is this:

Language constructions that function as type names denote a different type each time they occur.

The declarations of TArray1 and TArray2 fall into this category. And that means that these two identifiers denote different types.

Now we need to look at the section discussing compatibility. This gives a set of rules to follow to determine whether or not two types are compatible or assignment compatible. We can in fact shortcut that discussion by referring to another help topic: Structured Types, Array Types and Assignments which states clearly:

Arrays are assignment-compatible only if they are of the same type.

This makes it clear why the assignment Array1 := Array2 results in a compiler error.

Your code looked at passing parameters, but mine focused on assignment. The issues are the same because, as the Calling Procedures and Functions help topic explains:

When calling a routine, remember that:

  • expressions used to pass typed const and value parameters must be assignment-compatible with the corresponding formal parameters.
  • …….

Leave a Comment