C.4 Type checking errors

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

Error 4000: Type mismatch

This can happen in many cases:
Error 4001: Incompatible types: got ”arg. 1” expected ”arg. 2

There is no conversion possible between the two types. Another possibility 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 4002: Type mismatch between ”arg. 1” and ”arg. 2

The types are not equal.
Error 4003: Type identifier expected

The identifier is not a type, or you forgot to supply a type identifier.
Error 4004: 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 4005: Integer expression expected, but got ”arg. 1

The compiler expects an expression of type integer, but gets a different type.
Error 4006: Boolean expression expected, but got ”arg. 1

The expression must be a boolean type. It should be return True or False.
Error 4007: 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 4008: Pointer type expected, but got ”arg. 1

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 4009: Class type expected, but got ”arg. 1

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 4011: Can’t evaluate constant expression

This error can occur when the bounds of an array you declared do not evaluate to ordinal constants.
Error 4012: 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 4013: 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 4014: 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 4015: 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 4016: String types have to match exactly in $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 4017: 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 4018: 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 4019: Can’t use readln or writeln on typed file

readln and writeln are only allowed for text files.
Error 4020: Can’t use read or write on untyped file.

read and write are only allowed for text or typed files.
Error 4021: 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 4022: 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 4023: Integer or real expression expected

The first argument to str must be a real or integer type.
Error 4024: Wrong type ”arg. 1” in array constructor

You are trying to use a type in an array constructor which is not allowed.
Error 4025: Incompatible type for arg no. arg. 1: Got ”arg. 2”, expected ”arg. 3

You are trying to pass an invalid type for the specified parameter.
Error 4026: Method (variable) and Procedure (variable) are not compatible

You cannot assign a method to a procedure variable or a procedure to a method pointer.
Error 4027: 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 4028: Can’t take the address of constant expressions

It is not possible to get the address of a constant expression, because they are not 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 4029: Argument cannot 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 4030: 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 4031: 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 4032: 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 4033: 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 4034: Interface type expected, but got ”arg. 1

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 4035: Mixing signed expressions and longwords gives a 64 bit 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 4036: 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 4037: Typecast has different size (arg. 1-¿ arg. 2) in assignment

Type casting to a type with a different size is not allowed when the variable is used in an assignment.
Error 4038: Enums with assignments cannot 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 4039: Class or Object types ”arg. 1” and ”arg. 2” 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 4040: Class types ”arg. 1” and ”arg. 2” 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 4041: Class or interface type expected, but got ”arg. 1

The compiler expected a class or interface name, but got another type or identifier.
Error 4042: Type ”arg. 1” 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 4043: 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 4044: Comparison might be always false due to range of constant and expression

There is a comparison between a constant and an expression where the constant is out of the valid range of values of the expression. Because of type promotion, the statement will always evaluate to false. Explicitly typecast the constant or the expression to the correct range to avoid this warning if you think the code is correct.
Warning 4045: Comparison might be always true due to range of constant and expression

There is a comparison between a constant and an expression where the constant is out of the valid range of values of the expression. Because of type promotion, the statement will always evaluate to true. Explicitly typecast the constant or the expression to the correct range to avoid this warning if you think the code is correct.
Warning 4046: Constructing a class ”arg. 1” with abstract method ”arg. 2

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 4047: 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 4048: 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 4049: 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 4050: The address of an abstract method cannot be taken

An abstract method has no body, so the address of an abstract method cannot be taken.
Error 4051: 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 4052: Constant Expression expected

The compiler expects an constant expression, but gets a variable expression.
Error 4053: Operation ”arg. 1” not supported for types ”arg. 2” and ”arg. 3

The operation is not allowed for the supplied types.
Error 4054: Illegal type conversion: ”arg. 1” to ”arg. 2

When doing a type-cast, you must take care that the sizes of the variable and the destination type are the same.
Hint 4055: 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 4056: 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 4057: 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 4058: Illegal counter variable

The type of a for loop variable must be an ordinal type. Loop variables cannot be reals or strings.
Warning 4059: 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 4060: Class or COM interface type expected, but got ”arg. 1

Some operators, such as the AS operator, are only applicable to classes or COM interfaces.
Error 4061: Constant packed arrays are not yet supported

You cannot declare a (bit)packed array as a typed constant.
Error 4062: Incompatible type for arg no. arg. 1: Got ”arg. 2” expected ”(Bit)Packed Array”

The compiler expects a (bit)packed array as the specified parameter.
Error 4063: Incompatible type for arg no. arg. 1: Got ”arg. 2” expected ”(not packed) Array”

The compiler expects a regular (i.e., not packed) array as the specified parameter.
Error 4064: 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 4065: Constant packed records and objects are not yet supported

You cannot declare a (bit)packed array as a typed constant at this time.
Warning 4066: Arithmetic ”arg. 1” 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 4076: Can’t take address of a subroutine marked as local

The address of a subroutine marked as local cannot be taken.
Error 4077: Can’t export subroutine marked as local from a unit

A subroutine marked as local cannot be exported from a unit.
Error 4078: Type is not automatable: ”arg. 1

Only byte, integer, longint, smallint, currency, single, double, ansistring, widestring, tdatetime, variant, olevariant, wordbool and all interfaces are automatable.
Hint 4079: Converting the operands to ”arg. 1” 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 4080: Converting the operands to ”arg. 1” 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 4081: Converting the operands to ”arg. 1” 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 4082: 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 4083: Interface type arg. 1has 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 4084: Invalid selector name ”arg. 1

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 4085: Expected Objective-C method, but got arg. 1

A selector can only be created for Objective-C methods, not for any other kind of procedure/function/method.
Error 4086: 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 4087: 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).
Error 4088: Ordinal or string expression expected

The expression must be an ordinal or string type.
Error 4089: String expression expected

The expression must be a string type.
Warning 4090: Converting 0 to NIL

Use NIL rather than 0 when initialising a pointer.
Error 4091: Objective-C protocol type expected, but got ”arg. 1

The compiler expected a protocol type name, but found something else.
Error 4092: The type ”arg. 1” is not supported for interaction with the Objective-C and the blocks runtime.

Objective-C and Blocks make extensive use of run time type information (RTTI). This format is defined by the maintainers of the run time and can therefore not be adapted to all possible Object Pascal types. In particular, types that depend on reference counting by the compiler (such as ansistrings and certain kinds of interfaces) cannot be used as fields of Objective-C classes, cannot be directly passed to Objective-C methods or Blocks, and cannot be encoded using objc_encode.
Error 4093: Class or objcclass type expected, but got ”arg. 1

It is only possible to create class reference types of class and objcclass
Error 4094: Objcclass type expected

The compiler expected an objcclass type
Warning 4095: Coerced univ parameter type in procedural variable may cause crash or memory corruption: arg. 1to arg. 2

univ parameters are implicitly compatible with all types of the same size, also in procedural variable definitions. That means that the following code is legal, because single and longint have the same size:
 {$mode macpas}  
 Type  
   TIntProc = procedure (l: univ longint);  
 
   procedure test(s: single);  
     begin  
       writeln(s);  
     end;  
 
   var  
     p: TIntProc;  
   begin  
     p:=test;  
     p(4);  
   end.  
 

This code may however crash on platforms that pass integers in registers and floating point values on the stack, because then the stack will be unbalanced. Note that this warning will not flag all potentially dangerous situations. when test returns.

Error 4096: Type parameters of specializations of generics cannot reference the currently specialized type

Recursive specializations of generics like Type MyType = specialize MyGeneric<MyType>; are not possible.
Error 4097: Type parameters are not allowed on non-generic class/record/object procedure or function

Type parameters are only allowed for methods of generic classes, records or objects
Error 4098: Generic declaration of ”arg. 1” differs from previous declaration

Generic declaration does not match the previous declaration
Error 4099: Helper type expected

The compiler expected a class helper type.
Error 4100: Record type expected

The compiler expected a record type.
Error 4101: Derived class helper must extend a subclass of ”arg. 1” or the class itself

If a class helper inherits from another class helper the extended class must extend either the same class as the parent class helper or a subclass of it
Error 4102: Derived record or type helper must extend ”arg. 1

If a record helper inherits from another record helper it must extend the same record that the parent record helper extended.
Error 4103: Invalid assignment, procedures return no value

This error occurs when one tries to assign the result of a procedure or destructor call. A procedure or destructor returns no value so this is not possible.
Warning 4104: Implicit string type conversion from ”arg. 1” to ”arg. 2

An implicit type conversion from an ansi string type to an unicode string type is encountered. To avoid this warning perform an explicit type conversion.
Warning 4105: Implicit string type conversion with potential data loss from ”arg. 1” to ”arg. 2

An implicit type conversion from an unicode string type to an ansi string type is encountered. This conversion can lose data since not all unicode characters may be represented in the codepage of destination string type.
Warning 4106: Explicit string typecast from ”arg. 1” to ”arg. 2

An explicit typecast from an ansi string type to an unicode string type is encountered. This warning is off by default. You can turn it on to see all suspicious string conversions.
Warning 4107: Explicit string typecast with potential data loss from ”arg. 1” to ”arg. 2

An explicit typecast from an unicode string type to an ansi string type is encountered. This conversion can lose data since not all unicode characters may be represented in the codepage of destination string type. This warning is off by default. You can turn it on to see all the places with lossy string conversions.
Warning 4108: Unicode constant cast with potential data loss

Conversion from a WideChar to AnsiChar can lose data since now all unicode characters may be represented in the current system codepage You can nest function definitions only 31 levels deep.
Error 4109: Range check error while evaluating constants (arg. 1must be between arg. 2and arg. 3)

Warning 4110: Range check error while evaluating constants (arg. 1must be between arg. 2and arg. 3)

The constants are outside their allowed range.
Error 4111: This type is not supported for the Default() intrinsic

Some types like for example Text and File Of X are not supported by the Default intrinsic.
Error 4112: JVM virtual class methods cannot be static

Virtual class methods cannot be static when targeting the JVM platform, because the self pointer is required for correct dispatching.
Error 4113: Final (class) fields can only be assigned in their class’ (class) constructor

It is only possible to assign a value to a final (class) field inside a (class) constructor of its owning class.
Error 4114: It is not possible to typecast untyped parameters on managed platforms, simply assign a value to them instead.

On managed platforms, untyped parameters are translated by the compiler into the equivalent of var x: BaseClassType. Non-class-based types passed to such parameters are automatically wrapped (or boxed) in a class, and after the call the potentially modified value is assigned back to the original variable. On the caller side, changing untyped var/out parameters happens by simply assigning values to them (either class-based or primitive ones). On the caller side, they will be extracted and if their type does not match the original variable’s, an exception will be raised.
Error 4115: The assignment side of an expression cannot be typecasted to a supertype on managed platforms

Managed platforms guarantee type safety at the bytecode level. This means that the virtual machine must be able to statically determine that no type-unsafe assignments or operations occur. By assigning a parent class type to a variable of a child type by typecasting the assignment side to the parent class type, the type safety would no longer be guaranteed and the generated code would fail verification at run time time.
Warning 4116: The interface method ”arg. 1” raises the visibility of ”arg. 2” to public when accessed via an interface instance

Error 4117: The interface method ”arg. 1” has a higher visibility (public) than ”arg. 2

All methods in an interface have always public visibility. That means that if an interface method is implemented using a (strict) protected or private method, this method is actually publicly accessible via the interface. On the JVM target this situation results in an error because the JVM rejects such attempts to circumvent the visibility rules. On other targets this is a warning that is disabled by default because such situations are common practice, but it can be enabled in case you are concerned with keeping your code compilable for the JVM target.
Error 4118: TYPEOF can only be used on object types with VMT

Typeof() intrinsic returns pointer to VMT of its argument. It cannot be used on object types that do not have VMT.
Error 4119: It is not possible to define a default value for a parameter of type ”arg. 1

Parameters declared as structured types, such as files, variants, non-dynamic arrays and TP-style objects, cannot have a default value.
Error 4120: Type ”arg. 1” cannot be extended by a type helper

Types like procedural variables cannot be extended by type helpers
Error 4121: Procedure or function must be far in order to allow taking its address: ”arg. 1

In certain i8086 memory models (medium, large and huge), procedures and functions have to be declared ’far’ in order to allow their address to be taken.
Warning 4122: Creating an instance of abstract class ”arg. 1

The specified class is declared as abstract and thus no instance of this class should be created. This is merely a warning for Delphi compatibility.
Error 4123: Subroutine references cannot be declared as ”of object” or ”is nested”, they can always refer to any kind of subroutine

Subroutine references can refer to any kind of subroutine and hence do not require specialisation for methods or nested subroutines.
Error 4124: Procedure variables in that memory model do not store segment information

Warning 4125: The first value of a set constructur range is greater then the second value, so the range describes an empty set.

If a set is constructed like this: s:=[9..7];], then an empty set is generated. As this is something normally not desired, the compiler warns about it.
Error 4126: C block reference must use CDECL or MWPASCAL calling convention.

When declaring a C block reference ensure that it uses either the cdecl or mwpascal calling convention either by adding the corresponding function directive or by using the {$Calling} compiler directive.
Error 4127: The interface type of the forward declaration and the declared interface type do not match for interface arg. 1

When declaring an interface forward, the interface type must be the same as at the actual declaration of the interface. This is in particular important with regard to the parent interface which implicitly sets the interface type for the child interface.
Error 4128: Type not allowed for generic constant parameter: arg. 1

Only types that can also be used (indirectly) for untyped constants can be used as a type for a generic constant parameter.
Error 4129: Can’t read or write variables of this type in iso mode

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 in the selected language mode (iso mode).
Warning 4130: The length of the constant string (length is arg. 1) must be equal to the number of array elements (arg. 2elements)

ISO Pascal requires that string constants have the same length as the array to which them they are assigned.
Error 4131: A nested function variable can not be assigned to a function reference.

Function references can live beyond the scope of the function they’re contained in while nested functions assigned to nested function variables can’t. Due to this discrepancy in design assigning a nested function variable to a function reference is forbidden.
Error 4132: Cannot take the address of a WebAssembly externref

WebAssembly externref types don’t have an in-memory representation and therefore, their address cannot be taken.
Error 4133: WebAssembly reference types don’t have an observable size

WebAssembly reference types are opaque, meaning neither their size, nor their bit pattern can be observed.