Skip to content

generics: defer constraint checks for implementation-header parameters (fixes upstream#41770) - #50

Open
Moonbot-Tech wants to merge 2 commits into
unleashedpascal:mainfrom
Moonbot-Tech:fix-41770
Open

generics: defer constraint checks for implementation-header parameters (fixes upstream#41770)#50
Moonbot-Tech wants to merge 2 commits into
unleashedpascal:mainfrom
Moonbot-Tech:fix-41770

Conversation

@Moonbot-Tech

Copy link
Copy Markdown

Problem. FPC issue #41770: a Delphi-style implementation of a generic routine does not repeat the constraints of its declaration. While the implementation header is parsed, the fresh type parameter is still an undefineddef, and the constraint check rejected it ("Class type expected, but got T") before it could be matched with the already validated declaration.

Fix. In pgenutil.pas skip the check only for an undefined generic parameter of an implementation header when a generic declaration with the same name and arity exists; complete header matching is still required afterwards, so mismatched headers, forwards and standalone unconstrained generics are rejected as before.

Test. tests/webtbs/tw41770.pp: rejected on current main, runs after the fix.

Validation. Win64 build of main (a359fc1) with the patch; 405 neighbouring tests from tests/test (inline, rtti, helpers, generics, opt) give identical results before and after.

🤖 Generated with Claude Code

…s (fixes upstream#41770)

A Delphi-style implementation of a generic routine does not repeat the
constraints of its declaration. While the implementation header is
parsed, the fresh type parameter is still an undefineddef, and the
constraint check rejected it ("Class type expected, but got T") before
it could be matched with the already validated declaration.

Skip the check only for an undefined generic parameter of an
implementation header when a generic declaration with the same name and
arity exists; complete header matching is still required afterwards.

FPC issue: https://gitlab.com/freepascal.org/fpc/source/-/issues/41770

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@fibodevy fibodevy added the waiting-upstream Stock FPC fix, waits for the upstream MR to be merged or rejected label Sep 6, 2026
@Moonbot-Tech

Copy link
Copy Markdown
Author

Keep a valid implementation-header/runtime control and reject invalid concrete specialization at the call site, invalid body specialization and a mismatched implementation signature. These cover distinct phases rather than repeating the accepted example.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

waiting-upstream Stock FPC fix, waits for the upstream MR to be merged or rejected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants