Recent

Author Topic: overloaded methods give a strange compiler error  (Read 1644 times)

soerensen3

  • Full Member
  • ***
  • Posts: 213
overloaded methods give a strange compiler error
« on: July 15, 2020, 10:44:02 pm »
When I try to compile an application I wrote with trunk laz and fpc I get a strange compiler error which is to my understanding a bug.
I made this minimal example unit.

Code: Pascal  [Select][+][-]
  1. unit Unit2;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils;
  9.  
  10. type
  11.   TTokenKind = ( tkSymbol, tkIdentifier );
  12.  
  13.   TParser = class
  14.     public
  15.       function Expect( ATokenKind: TTokenKind ): Boolean; overload;
  16.       function Expect( ATokenKind: TTokenKind; AText: String ): Boolean; overload:
  17.   end;
  18.  
  19.  
  20. implementation
  21.  
  22. end.
  23.  
The error messages:
Quote
Compile Project, Target: /home/johannes/tmp/project1: Exit code 1, Errors: 2
unit2.pas(16,82) Error: Fields cannot appear after a method or property definition, start a new visibility section first
unit2.pas(20,1) Fatal: Syntax error, "identifier" expected but "IMPLEMENTATION" found

I'm on Manjaro linux but I don't think it matters.
It happens on both objfpc and delphi mode.
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

Bart

  • Hero Member
  • *****
  • Posts: 5570
    • Bart en Mariska's Webstek
Re: overloaded methods give a strange compiler error
« Reply #1 on: July 15, 2020, 10:48:39 pm »
The colon (:) after the last overload needs to be a semicolon (;).
So, it's just a typo.

Bart

soerensen3

  • Full Member
  • ***
  • Posts: 213
Re: overloaded methods give a strange compiler error
« Reply #2 on: July 15, 2020, 10:53:50 pm »
 >:D
It took me only 2 days to update both my lazarus and fpc because fpcupdeluxe was refusing to work and the packages of arch for lazarus seem to be broken. Also the AUR package of Lazarus did not compile. And someone else finds the error in a matter of seconds.

I should probably get more sleep.  :P

Thanks bye the way!
Lazarus 1.9 with FPC 3.0.4
Target: Manjaro Linux 64 Bit (4.9.68-1-MANJARO)

440bx

  • Hero Member
  • *****
  • Posts: 5439
Re: overloaded methods give a strange compiler error
« Reply #3 on: July 15, 2020, 11:21:47 pm »
Code: Pascal  [Select][+][-]
  1.       function Expect( ATokenKind: TTokenKind; AText: String ): Boolean; overload:
  2.  
The error messages:
Quote
unit2.pas(16,82) Error: Fields cannot appear after a method or property definition, start a new visibility section first

And someone else finds the error in a matter of seconds.

I should probably get more sleep.  :P
Probably <chuckle>... if you look at that error message on line 16 it point to column 82 which is the colon, that's the clue. 

Sometimes it takes looking at the statement and the compiler message for a few seconds before finally figuring out what the problem really is. 
(FPC v3.0.4 and Lazarus 1.8.2) or (FPC v3.2.2 and Lazarus v4.0rc3) on Windows 7 SP1 64bit.

 

TinyPortal © 2005-2018