Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2021-01

Error: Global Generic template references static symtable

8 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Bart

Hi,

While trying to solve https://bugs.freepascal.org/view.php?id=38306 I got this error I have never seen before.

_gdeque.pp(249,4) Error: Global Generic template references static symtable _gdeque.pp(302) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted

Line 249 is the "end;" of a method (IncreaseCapacity) of a generic class.

If I remove this line the error goes away:

Elems := Min(EmptyElems, FStart);
Elems and EmptyElems are local vars to that method. FStart is a private variable of the class.

function Min(const A,B: SizeUInt): SizeUInt;  //no need to drag in the
entire Math unit ;-)
begin
  if (A<B) then
    Result := A
  else
    Result := B;
end;

This function is not part of the class definition. I defined it in the implementation section of the unit.

Once I moved that function to be a nested function of the method IncreaseCapacity (it's only used there), the error goes away.

It seems I cannot use a stand-alone function that is declared in the implementation of the unit?
Why is that?

Bart

Bart

Reply by email

Sven Barth
to Bart

Bart via fpc-devel schrieb am Fr., 8. Jan.
2021, 20:07:

It seems I cannot use a stand-alone function that is declared in the implementation of the unit?

Correct.

Why is that?

Generics are a stream of tokens that is reparsed when specialized. Functions declared in the implementation section are simply not available then thus its forbidden right away. This is Delphi compatible.

Regards,
Sven

Reply by email

Bart
to Sven Barth
PM Sven Barth wrote
> It seems I cannot use a stand-alone function that is declared in the > implementation of the unit? Generics are a stream of tokens that is reparsed when specialized. Functions declared in the implementation section are simply not available then thus its forbidden right away. This is Delphi compatible.

Thanks for explaining this.
The errormessage is probably technically correct, but for me it might be a little more informative (so that I can tell what I did wrong).

Bart

Reply by email

Sven Barth
to Bart

Bart via fpc-devel schrieb am Sa., 9. Jan.
2021, 05:17:

Show quoted text 14 lines
On Fri, Jan 8, 2021 at 9:00 PM Sven Barth via fpc-devel wrote: >> It seems I cannot use a stand-alone function that is declared in the >> implementation of the unit? > Generics are a stream of tokens that is reparsed when specialized. Functions declared in the implementation section are simply not available then thus its forbidden right away. This is Delphi compatible. Thanks for explaining this. The errormessage is probably technically correct, but for me it might be a little more informative (so that I can tell what I did wrong).

Right click the error message in Lazarus, then click "Help". For me a dialog with the following text appeared:

"A generic declared in the interface section of a unit must not reference symbols that belong solely to the implementation section of that unit."

The *why* is not important for users. Those that are interested can ask, just like you did.

Regards,
Sven

Reply by email

Bart
to Sven Barth
PM Sven Barth wrote
Right click the error message in Lazarus, then click "Help". For me a dialog with the following text appeared:

Hah!
Learned something new today!

The *why* is not important for users. Those that are interested can ask, just like you did.

Then let me rephrase it.
Error messages of the compiler normally point you in the right direction like:

  qtest.lpr(367,3) Fatal: Syntax error, ";" expected but "identifier

TESTINCCAP" found
It's sort of obvious there is a missing semicolon.

OTOH: "Global Generic template references static symtable" only means something to me (as an fpc user) if I know what a static symtable is (I assume this is an internal datastructure in the compiler). Since I have no clue, I have absolutely no idea how to fix that error. In my case I commented out all lines in the given procedure and uncommented them one by one to finally get at the offending line in question.
I then made an educated guess that (sine accessing functions like Format() is OK), it must have something to do with the declaration of the "Min()" function.

It would have helped if the error message was a little less cryptic, and/or if it pointed to the line that caused the error in the first place.

Of course I have no idea wether or not this error message only applies to the situation I encountered...

Bart

Bart

Reply by email

Sven Barth
to Bart
Bart wrote 22 lines
> The *why* is not important for users. Those that are interested can ask, just like you did. Then let me rephrase it. Error messages of the compiler normally point you in the right direction like: qtest.lpr(367,3) Fatal: Syntax error, ";" expected but "identifier TESTINCCAP" found It's sort of obvious there is a missing semicolon. OTOH: "Global Generic template references static symtable" only means something to me (as an fpc user) if I know what a static symtable is (I assume this is an internal datastructure in the compiler). Since I have no clue, I have absolutely no idea how to fix that error. In my case I commented out all lines in the given procedure and uncommented them one by one to finally get at the offending line in question. I then made an educated guess that (sine accessing functions like Format() is OK), it must have something to do with the declaration of the "Min()" function. It would have helped if the error message was a little less cryptic, and/or if it pointed to the line that caused the error in the first place.

I have clarified the message a bit.

Displaying the message at the correct location would be more involved... you might want to open a bug report for that so that it's remembered somewhere, but it's definitely going to be a low priority one.

Regards,
Sven

Reply by email

Sven Barth
to Bart

Bart via fpc-devel schrieb am Mo., 11.
Jan. 2021, 03:42:

Show quoted text 8 lines
On Sun, Jan 10, 2021 at 11:59 AM Sven Barth via fpc-devel wrote: > Displaying the message at the correct location would be more involved... > you might want to open a bug report for that so that it's remembered > somewhere, but it's definitely going to be a low priority one. https://bugs.freepascal.org/view.php?id=38342

Thanks.

Regards,
Sven

Reply by email