tb0148.pp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. { %OPT=-Sg }
  2. { Old file: tbs0178.pp }
  3. { problems with undefined labels and fail outside constructor OK 0.99.9 (PM) }
  4. PROGRAM NoLabel; { this program compiles fine with TP but not with FP }
  5. type
  6. ptestobj = ^ttestobj;
  7. ttestobj = object
  8. constructor init;
  9. procedure test_self;
  10. end;
  11. const
  12. allowed : boolean = false;
  13. constructor ttestobj.init;
  14. begin
  15. if not allowed then
  16. fail;
  17. end;
  18. procedure ttestobj.test_self;
  19. function myself : ptestobj;
  20. begin
  21. myself:=@self;
  22. end;
  23. begin
  24. if myself<>@self then
  25. begin
  26. Writeln('problem with self');
  27. Halt(1);
  28. end;
  29. end;
  30. LABEL
  31. N1,
  32. N2,
  33. FAIL, { this is a reserved word in constructors only! - FP fails here
  34. }
  35. More; { label not defined - FP fails, but a warning is enough for that
  36. }
  37. { since label referenced nowhere }
  38. var ptest : ptestobj;
  39. self : longint;
  40. BEGIN
  41. new(ptest,init);
  42. if ptest<>nil then
  43. begin
  44. Writeln('Fail does not work !!');
  45. Halt(1);
  46. end;
  47. allowed:=true;
  48. new(ptest,init);
  49. if ptest=nil then
  50. begin
  51. Writeln('Constructor does not work !!');
  52. Halt(1);
  53. end
  54. else
  55. ptest^.test_self;
  56. N1: Write;
  57. N2: Write;
  58. FAIL: Write;
  59. self:=1;
  60. END.