View Issue Details

IDProjectCategoryView StatusLast Update
0023496LazarusIDEpublic2014-10-07 10:34
ReporterSven Barth Assigned ToMattias Gaertner  
Status resolvedResolutionfixed 
Summary0023496: Add support for generic constraints to CodeTools
DescriptionFree Pascal now supports constraints for generics, so Lazarus should support these as well.

Support for such constraints contains two steps:
* correctly parse the constraint syntax (see Additional Information)
* handle type parameters correctly (e.g. if a type parameter has a constraint for a specific class the class' methods should be listed in the completion list)
Additional InformationThe syntax for type constraints looks as follows:

  generic TSomeGeneric<T1, T2: "Constraints"; T3; T4: "Constraints"> = class

where "Constraints" currently is:
- "record" keyword (mutually exclusive to other constraints)
- "class" keyword (mutually exclusive to "record")
- "constructor" keyword (Delphi mode only; mutually exclusive to "record")
- class identifier (mutually exclusive to "record" and "class")
- interface identifier (mutually exclusive to "record")

Multiple interface identifiers can be given together with the "class" or "constructor" keywords as well as a class identifier; the of the constraints is not important.

The "constructor" constraint behaves the same as the "class" constraint.

For further examples please take a look at $fpcdir/tests/test/ugenconstraints.pas (from FPC revision 23158 on).
TagsNo tags attached.
Fixed in Revision39822
Attached Files


related to 0023617 closedMattias Gaertner Patches [patch][codetools] Allow CTRL+Space if there is generic with constraints defined. 
related to 0023782 resolvedJuha Manninen Lazarus Autocomplete with generics 


Mattias Gaertner

2013-01-10 18:15

manager   ~0064802

Implemented: correctly parse the constraint syntax

Sven Barth

2013-01-11 16:24

manager   ~0064819

That's a good first step. :)

Btw: I like your idea to add a tool to test the parsing of FPC test units ^^


Sven Barth

2013-03-01 18:46

manager   ~0065972

I've found a little problem with the current implementation in mode Delphi.

Consider this code:

=== example begin ===

  TTest<T: class> = class
    procedure Test;

=== example end ===

If I now do Ctrl+Shift+C the following body will be created:

=== example begin ===

procedure TTest<T: class>.Test;


=== example end ===
This is not correct. The constraints must not appear in the implementation of the method. Also Ctrl+Shift+Up/Down does not work correctly (neither with nor without ": class" in the implementation). Sometimes Ctrl+Shift+Up behaves correctly, but Ctrl+Shift+Down does not seem able to find the method again. Another Ctrl+Shift+C after removing the ": class" in the implementation will add a new "TTest<T: class>.Test" method.


Mattias Gaertner

2013-03-01 20:48

manager   ~0065973

Class completion now works in mode Delphi.

Vincent Snijders

2014-10-07 06:28

manager   ~0078036

Is there anything still to be done on this issue?
Yes, then Resolution should be open.
No, then Status should be resolved.

Issue History

Date Modified Username Field Change
2012-12-16 15:19 Sven Barth New Issue
2012-12-16 15:19 Sven Barth LazTarget => -
2013-01-09 16:27 Mattias Gaertner Relationship added related to 0023617
2013-01-09 16:27 Mattias Gaertner Status new => assigned
2013-01-09 16:27 Mattias Gaertner Assigned To => Mattias Gaertner
2013-01-10 18:15 Mattias Gaertner Fixed in Revision => 39822
2013-01-10 18:15 Mattias Gaertner Note Added: 0064802
2013-01-10 18:15 Mattias Gaertner Status assigned => confirmed
2013-01-10 18:15 Mattias Gaertner Resolution open => fixed
2013-01-11 16:24 Sven Barth Note Added: 0064819
2013-03-01 18:46 Sven Barth Note Added: 0065972
2013-03-01 20:48 Mattias Gaertner Note Added: 0065973
2014-09-25 08:12 Juha Manninen Relationship added related to 0023782
2014-10-07 06:28 Vincent Snijders Note Added: 0078036
2014-10-07 10:34 Mattias Gaertner Status confirmed => resolved