13.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 dierent declarations:
 Var  
    A1 : Array[1..10] Of Integer;  
    A2 : Array[1..10] Of Integer;  
 
 Begin  
    A1:=A2; { This statement gives also this error, it  
              is due the strict type checking of pascal }  
 End.  
 

Error: Type mismatch between "arg1" and "arg2"
The types are not equal
Error: Type identier expected
The identier is not a type, or you forgot to supply a type identier.
Error: Variable identier 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 dierent 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 of 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 identier that isn't a class.
Error: Can't evaluate constant expression
This error can occur when the bounds of an array you declared does not evaluate to ordinal constants
Error: Set elements are not compatible
You are trying to make 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 dened for sets like div mod ** (also >= <= for now)
Warning: Automatic type conversion from oating 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 procuce this message, because the result will then be of type real
Error: string types doesn't match, because of $V+ mode
When compiling in f$V+g 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
When you declared an enumeration type which has assignments in it, as in C, like in the following:
   Tenum = (a,b,e:=5);  
 

you cannot use the Succ or Pred functions on them.

Error: Can't read or write variables of this type
You are trying to read or write a variable from or to a le of type text, which doesn't support that. Only integer types, reals, pchars and strings can be read from/written to a text le. Booleans can only be written to text les.
Error: Can't use readln or writeln on typed le
readln and writeln are only allowed for text les.
Error: Can't use read or write on untyped le.
read and write are only allowed for text or typed les.
Error: Type conict 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. TP always uses a 16 bit lo/hi which returns always bits 0..7 for lo and the bits 8..15 for hi. If you want the TP behavior you have to type cast the argument to word/integer
Error: Integer or real expression expected
The rst argument to str must 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 specied 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 denition range of these functions.
Error: Can't get the address of constants
It is not possible to get the address of a constant, because they aren't stored in memory, you can try making it a typed constant.
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 argument Remark: Properties can be only used on the left side of an assignment, but 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 of local procedure/function is dierent. 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 identier 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 make the parameter as a value parameter or a var.
Error: Array type required
If you are accessing a variable using an index '[]' then the type must be an array. In FPC mode also a pointer is allowed.
Error: interface type expected, but got "arg1"
Warning: 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 overow 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 64bit which is slower than normal 32bit arithmetic. You can avoid this by typecasting one operand so it matches the resulttype 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 resulttype of the other one.
Error: Typecast has dierent size (arg1 -> arg2) in assignment
Type casting to a type with a dierent size is not allowed when the variable is used for assigning.
Error: enums with assignments can't be used as array index
When you declared an enumeration type which has assignments in it, as in C, like in the following:
   Tenum = (a,b,e:=5);  
 

you cannot use it as 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 or object to another while the class/object are not related. This will probably lead to errors
Error: Class or interface type expected, but got "arg1"
Error: Type "arg1" is not completely dened
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
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. Exlicitly 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. Exlicitly typecast the constant to the correct range to avoid this problem.
Warning: Constructing a class "arg1" with abstract methods
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 overriden.
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 ts within 8-bits, this may lead to range check errors. The in operator currently only supports a left operand which ts within a byte. In the case of enumerations, the size of an element of an enumeration can be controlled with the f$PACKENUMg or f$Zng 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: The operator is not applicable for the operand type
You are trying an operator that is not available for the type of the operands
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-bit for pointer storage.
Warning: Conversion between ordinals and pointers is not portable
If you typecast a pointer to a ordinal type of a dierent size (or vice-versa), this can cause problems. This is a warning to help nding the 32bit specic 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.