C.4 Type checking errors

This section lists all errors that can occur when type checking is performed.

Error: Type mismatch
This can happen in many cases:
Error: Incompatible types: got ”arg1” expected ”arg2”
There is no conversion possible between the two types. Another possiblity is that they are declared in different declarations:
 Var  
    A1 : Array[1..10] Of Integer;  
    A2 : Array[1..10] Of Integer;  
 
 Begin  
    A1:=A2; { This statement also gives this error. It  
              is due to the strict type checking of Pascal }  
 End.  
 

Error: Type mismatch between ”arg1” and ”arg2”
The types are not equal.
Error: Type identifier expected
The identifier is not a type, or you forgot to supply a type identifier.
Error: Variable identifier expected
This happens when you pass a constant to a routine (such as Inc var or Dec) when it expects a variable. You can only pass variables as arguments to these functions.
Error: Integer expression expected, but got ”arg1”
The compiler expects an expression of type integer, but gets a different type.
Error: Boolean expression expected, but got ”arg1”
The expression must be a boolean type. It should be return True or False.
Error: Ordinal expression expected
The expression must be of ordinal type, i.e., maximum a Longint. This happens, for instance, when you specify a second argument to Inc or Dec that doesn’t evaluate to an ordinal value.
Error: pointer type expected, but got ”arg1”
The variable or expression isn’t of the type pointer. This happens when you pass a variable that isn’t a pointer to New or Dispose.
Error: class type expected, but got ”arg1”
The variable or expression isn’t of the type class. This happens typically when
  1. The parent class in a class declaration isn’t a class.
  2. An exception handler (On) contains a type identifier that isn’t a class.
Error: Can’t evaluate constant expression
This error can occur when the bounds of an array you declared do not evaluate to ordinal constants.
Error: Set elements are not compatible
You are trying to perform an operation on two sets, when the set element types are not the same. The base type of a set must be the same when taking the union.
Error: Operation not implemented for sets
several binary operations are not defined for sets. These include: div, mod, **, >= and <=. The last two may be defined for sets in the future.
Warning: Automatic type conversion from floating type to COMP which is an integer type
An implicit type conversion from a real type to a comp is encountered. Since comp is a 64 bit integer type, this may indicate an error.
Hint: use DIV instead to get an integer result
When hints are on, then an integer division with the ’/’ operator will produce this message, because the result will then be of type real.
Error: string types doesn’t match, because of $V+ mode
When compiling in {$V+} mode, the string you pass as a parameter should be of the exact same type as the declared parameter of the procedure.
Error: succ or pred on enums with assignments not possible
If you declare an enumeration type which has C-like assignments in it, such as in the following:
   Tenum = (a,b,e:=5);  
 

then you cannot use the Succ or Pred functions with this enumeration.

Error: Can’t read or write variables of this type
You are trying to read or write a variable from or to a file of type text, which doesn’t support that variable’s type. Only integer types, reals, pchars and strings can be read from or written to a text file. Booleans can only be written to text files.
Error: Can’t use readln or writeln on typed file
readln and writeln are only allowed for text files.
Error: Can’t use read or write on untyped file.
read and write are only allowed for text or typed files.
Error: Type conflict between set elements
There is at least one set element which is of the wrong type, i.e. not of the set type.
Warning: lo/hi(dword/qword) returns the upper/lower word/dword
Free Pascal supports an overloaded version of lo/hi for longint/dword/int64/qword which returns the lower/upper word/dword of the argument. Turbo Pascal always uses a 16 bit lo/hi which always returns bits 0..7 for lo and the bits 8..15 for hi. If you want the Turbo Pascal behavior you have to type cast the argument to a word or integer.
Error: Integer or real expression expected
The first argument to str must be a real or integer type.
Error: Wrong type ”arg1” in array constructor
You are trying to use a type in an array constructor which is not allowed.
Error: Incompatible type for arg no. arg1: Got ”arg2”, expected ”arg3”
You are trying to pass an invalid type for the specified parameter.
Error: Method (variable) and Procedure (variable) are not compatible
You can’t assign a method to a procedure variable or a procedure to a method pointer.
Error: Illegal constant passed to internal math function
The constant argument passed to a ln or sqrt function is out of the definition range of these functions.
Error: Can’t take the address of constant expressions
It is not possible to get the address of a constant expression, because they aren’t stored in memory. You can try making it a typed constant. This error can also be displayed if you try to pass a property to a var parameter.
Error: Argument can’t be assigned to
Only expressions which can be on the left side of an assignment can be passed as call by reference arguments.

Remark: Properties can be used on the left side of an assignment, nevertheless they cannot be used as arguments.

Error: Can’t assign local procedure/function to procedure variable
It’s not allowed to assign a local procedure/function to a procedure variable, because the calling convention of a local procedure/function is different. You can only assign local procedure/function to a void pointer.
Error: Can’t assign values to an address
It is not allowed to assign a value to an address of a variable, constant, procedure or function. You can try compiling with -So if the identifier is a procedure variable.
Error: Can’t assign values to const variable
It’s not allowed to assign a value to a variable which is declared as a const. This is normally a parameter declared as const. To allow changing the value, pass the parameter by value, or a parameter by reference (using var).
Error: Array type required
If you are accessing a variable using an index ’[¡x¿]’ then the type must be an array. In FPC mode a pointer is also allowed.
Error: interface type expected, but got ”arg1”
The compiler expected to encounter an interface type name, but got something else. The following code would produce this error:
 Type  
   TMyStream = Class(TStream,Integer)  
 

Hint: Mixing signed expressions and longwords gives a 64bit result
If you divide (or calculate the modulus of) a signed expression by a longword (or vice versa), or if you have overflow and/or range checking turned on and use an arithmetic expression (+, -, *, div, mod) in which both signed numbers and longwords appear, then everything has to be evaluated in 64-bit arithmetic which is slower than normal 32-bit arithmetic. You can avoid this by typecasting one operand so it matches the result type of the other one.
Warning: Mixing signed expressions and cardinals here may cause a range check error
If you use a binary operator (and, or, xor) and one of the operands is a longword while the other one is a signed expression, then, if range checking is turned on, you may get a range check error because in such a case both operands are converted to longword before the operation is carried out. You can avoid this by typecasting one operand so it matches the result type of the other one.
Error: Typecast has different size (arg1 -¿ arg2) in assignment
Type casting to a type with a different size is not allowed when the variable is used in an assignment.
Error: enums with assignments can’t be used as array index
When you declared an enumeration type which has C-like assignments, such as in the following:
   Tenum = (a,b,e:=5);  
 

you cannot use it as the index of an array.

Error: Class or Object types ”arg1” and ”arg2” are not related
There is a typecast from one class or object to another while the class/object are not related. This will probably lead to errors.
Warning: Class types ”arg1” and ”arg2” are not related
There is a typecast from one class to another while the classes are not related. This will probably lead to errors.
Error: Class or interface type expected, but got ”arg1”
The compiler expected a class or interface name, but got another type or identifier.
Error: Type ”arg1” is not completely defined
This error occurs when a type is not complete: i.e. a pointer type which points to an undefined type.
Warning: String literal has more characters than short string length
The size of the constant string, which is assigned to a shortstring, is longer than the maximum size of the shortstring (255 characters).
Warning: Comparison is always false due to range of values
There is a comparison between an unsigned value and a signed constant which is less than zero. Because of type promotion, the statement will always evaluate to false. Explicitly typecast the constant to the correct range to avoid this problem.
Warning: Comparison is always true due to range of values
There is a comparison between an unsigned value and a signed constant which is less than zero. Because of type promotion, the statement will always evaluate to true. Explicitly typecast the constant to the correct range to avoid this problem.
Warning: Constructing a class ”arg1” with abstract method ”arg2”
An instance of a class is created which contains non-implemented abstract methods. This will probably lead to a runtime error 211 in the code if that routine is ever called. All abstract methods should be overridden.
Hint: The left operand of the IN operator should be byte sized
The left operand of the in operator is not an ordinal or enumeration which fits within 8 bits. This may lead to range check errors. The in operator currently only supports a left operand which fits within a byte. In the case of enumerations, the size of an element of an enumeration can be controlled with the {$PACKENUM} or {$Zn} switches.
Warning: Type size mismatch, possible loss of data / range check error
There is an assignment to a smaller type than the source type. This means that this may cause a range-check error, or may lead to possible loss of data.
Hint: Type size mismatch, possible loss of data / range check error
There is an assignment to a smaller type than the source type. This means that this may cause a range-check error, or may lead to possible loss of data.
Error: The address of an abstract method can’t be taken
An abstract method has no body, so the address of an abstract method can’t be taken.
Error: Assignments to formal parameters and open arrays are not possible
You are trying to assign a value to a formal (untyped var, const or out) parameter, or to an open array.
Error: Constant Expression expected
The compiler expects an constant expression, but gets a variable expression.
Error: Operation ”arg1” not supported for types ”arg2” and ”arg3”
The operation is not allowed for the supplied types.
Error: Illegal type conversion: ”arg1” to ”arg2”
When doing a type-cast, you must take care that the sizes of the variable and the destination type are the same.
Hint: Conversion between ordinals and pointers is not portable
If you typecast a pointer to a longint (or vice-versa), this code will not compile on a machine using 64 bits addressing.
Warning: Conversion between ordinals and pointers is not portable
If you typecast a pointer to an ordinal type of a different size (or vice-versa), this can cause problems. This is a warning to help in finding the 32-bit specific code where cardinal/longint is used to typecast pointers to ordinals. A solution is to use the ptrint/ptruint types instead.
Error: Can’t determine which overloaded function to call
You’re calling overloaded functions with a parameter that doesn’t correspond to any of the declared function parameter lists. e.g. when you have declared a function with parameters word and longint, and then you call it with a parameter which is of type integer.
Error: Illegal counter variable
The type of a for loop variable must be an ordinal type. Loop variables cannot be reals or strings.
Warning: Converting constant real value to double for C variable argument, add explicit typecast to prevent this.
In C, constant real values are double by default. For this reason, if you pass a constant real value to a variable argument part of a C function, FPC by default converts this constant to double as well. If you want to prevent this from happening, add an explicit typecast around the constant.
Error: Class or COM interface type expected, but got ”arg1”
Some operators, such as the AS operator, are only applicable to classes or COM interfaces.
Error: Constant packed arrays are not yet supported
You cannot declare a (bit)packed array as a typed constant.
Error: Incompatible type for arg no. arg1: Got ”arg2” expected ”(Bit)Packed Array”
The compiler expects a (bit)packed array as the specified parameter.
Error: Incompatible type for arg no. arg1: Got ”arg2” expected ”(not packed) Array”
The compiler expects a regular (i.e., not packed) array as the specified parameter.
Error: Elements of packed arrays cannot be of a type which need to be initialised
Support for packed arrays of types that need initialization (such as ansistrings, or records which contain ansistrings) is not yet implemented.
Error: Constant packed records and objects are not yet supported
You cannot declare a (bit)packed array as a typed constant at this time.
Warning: Arithmetic ”arg1” on untyped pointer is unportable to {$T+}, suggest typecast
Addition/subtraction from an untyped pointer may work differently in {$T+}. Use a typecast to a typed pointer.
Error: Can’t take address of a subroutine marked as local
The address of a subroutine marked as local can’t be taken.
Error: Can’t export subroutine marked as local from a unit
A subroutine marked as local can’t be exported from a unit.
Error: Type is not automatable: ”arg1”
Only byte, integer, longint, smallint, currency, single, double, ansistring, widestring, tdatetime, variant, olevariant, wordbool and all interfaces are automatable.
Hint: Converting the operands to ”arg1” before doing the add could prevent overflow errors.
Adding two types can cause overflow errors. Since you are converting the result to a larger type, you could prevent such errors by converting the operands to this type before doing the addition.
Hint: Converting the operands to ”arg1” before doing the subtract could prevent overflow errors.
Subtracting two types can cause overflow errors. Since you are converting the result to a larger type, you could prevent such errors by converting the operands to this type before doing the subtraction.
Hint: Converting the operands to ”arg1” before doing the multiply could prevent overflow errors.
Multiplying two types can cause overflow errors. Since you are converting the result to a larger type, you could prevent such errors by converting the operands to this type before doing the multiplication.
Warning: Converting pointers to signed integers may result in wrong comparison results and range errors, use an unsigned type instead.
The virtual address space on 32-bit machines runs from $00000000 to $ffffffff. Many operating systems allow you to allocate memory above $80000000. For example both Windows and linux allow pointers in the range $0000000 to $bfffffff. If you convert pointers to signed types, this can cause overflow and range check errors, but also $80000000 ¡ $7fffffff. This can cause random errors in code like ”if p¿q”.
Error: Interface type arg1 has no valid GUID
When applying the as-operator to an interface or class, the desired interface (i.e. the right operand of the as-operator) must have a valid GUID.
Error: Invalid selector name
An Objective-C selector cannot be empty, must be a valid identifier or a single colon, and if it contains at least one colon it must also end in one.
Error: Expected Objective-C method, but got arg1
A selector can only be created for Objective-C methods, not for any other kind of procedure/function/method.
Error: Expected Objective-C method or constant method name
A selector can only be created for Objective-C methods, either by specifying the name using a string constant, or by using an Objective-C method identifier that is visible in the current scope.
Error: No type info available for this type
Type information is not generated for some types, such as enumerations with gaps in their value range (this includes enumerations whose lower bound is different from zero).