Dear all,
while porting from CodeWarrior Object Pascal to GPC I noticed the following differences which might be worthwhile to address in GPC.
1) Mutual recursive object type declaration program prog1; { compile with gpc --mac-pascal prog1.pas } type t1 = object function f: t2; { error: unknown identifier `t2' } { above works in CodeWarrior Object Pascal as objects are always references } end;
t2 = object function g: t1; end;
function t1.f: t2; begin f := nil; end; function t2.g: t1; begin g := nil; end; begin end.
As a workaround this can be solved by introducing a common super class and subsequent casting.
2) Procedure type assignment compatibility with specialized parameters program prog2; { compile with gpc --mac-pascal prog2.pas } type baseType = object end;
derivedType = object(baseType) end;
procedure p1(x: baseType); begin end; procedure p2(x: derivedType); begin end; var pv: procedure(x: baseType); begin pv := p1; pv := p2; { error: incompatible types in assignment } end.
A workaround is to declare the x in p2 as baseType and perform a cast in the body of p2.
3) Cast in with statement program prog3; { compile with gpc --mac-pascal prog3.pas } type baseType = object end;
derivedType = object(baseType) procedure f; end;
procedure derivedType.f; begin end;
var a: baseType; b: derivedType;
begin new(b); a := b; derivedType(a).f; { ok } with derivedType(a) do { warning: `with' element is not a constant or an lvalue } f; { error: invalid lvalue in method call } { error: function call used as a statement } end.
A workaround is to use a temporary variable for the with statement.