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 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 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 Inc var or Dec procedure. 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 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 identifier that isn’t a class.
Error: Variable or type indentifier expected
The argument to the High or Low function is not a variable nor a type identifier.
Error: Can’t evaluate constant expression
No longer in use.
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 defined for sets like div mod ** (also ¿= ¡= for now)
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 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 {$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
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 file of type text, which doesn’t support that. Only integer types, booleans, reals, pchars and strings can be read from/written to a text file.
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. 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 first 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 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 get the address of constants
It’s 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 can’t 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 different. You can only assign local procedure/function to a void pointer.
Error: Can’t assign values to an address
It’s 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 make the parameter value or 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 also a pointer is allowed.
Warning: Mixing signed expressions and cardinals gives a 64bit result
If you divide (or calculate the modulus of) a signed expression by a cardinal (or vice versa), or if you have overflow and/or range checking turned on and use an arithmetical expression (+, -, *, div, mod) in which both signed numbers and cardinals appear, then everything has to be evaluated in 64bit which is slower than normal 32bit arithmetics. 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 cardinal 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 cardinal 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 different size (arg1 -¿ arg2) in assignment
Type casting to a type with a different size is not allowed when the variable is used for assigning.