Defer constraint checks for implementation-header generic parameters (Fixes #41770)

Summary

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 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.

Fixes #41770. Test: tests/webtbs/tw41770.pp.

System

  • Operating system: all (verified on Windows 11)
  • Processor architecture: all (verified on x86-64)
  • Device: Computer

What is the current bug behavior?

tw41770.pp(25,51) Error: Class type expected, but got "T"
tw41770.pp(25,26) Error: Function header doesn't match any method of this class "class Observe$1(<erroneous type>);"

What is the behavior after applying this patch?

The implementation header matches its declaration; the test exits 0.

Relevant logs and/or screenshots

Verified on x86_64-win64 main (2efddc1b): red before, green after. Also proposed to Unleashed Pascal as PR #50, which waits for this MR.

Additional boundary tests

Added tw41770a/b/c: invalid concrete specialization at a call site, invalid specialization in a generic body, and a mismatched implementation signature. Each rejects with the intended constraint/header diagnostic; the original positive runtime test passes at -O-, -O2 and -O3 on x86_64-win64. These check that implementation-header deferral does not disable validation in the later phases.

Edited by Moonbot

Merge request reports

Loading
Loading