fpc/tests/test/tgenconstraint11.pp
svenbarth 4adb36e8da Add support for generic type constraints. They are currently only useful to stop specialization of a generic. The parsing of a generic is still too lax and needs to be changed in the future...
symconst.pas:
  + extend "tdefoptions" by a "df_genconstraint" which will be used to mark dummy defs that should mainly satisfy the compiler's type checking without to much changes
symsym.pas:
  + add a class "tgenericconstraintdata" which will hold information about the constraints associated with a specific generic type parameter (designed for future extensions)
  + extend "ttypesym" by a reference to a "tgenericconstraintdata" which is written to the ppu only if needed
symtype.pas:
  + add a pointer to "tderef" as this is needed for the ppu reading/writing code for the "tgenericconstraintdata"
pdecl.pas, types_dec:
  + call "parse_generic_parameters" so that constraints are allowed
pgenutil.pas:
  + extend "generate_specialization" by a "parsedpos" to give in the file position of the first parsed parameter (needed for correct error locations when checking the constraints)
  + add an overloaded call of "generate_specialization" to differentiate between the use cases "first parameter parsed by generate_specialization" and "first parameter parsed by other code"; this also allows to write the "fillchar" for the "parampos" parameter only once ( => otherwise a warning is triggered => error in compilation)
  + extend the "parse_generic_specialization_types" by a "poslist" parameter which will contain the positions of all parsed type parameters (can only be used in the case that all parameters are parsed)
  * move the original code of "parse_generic_specialization_types" to a new procedure "parse_generic_specialization_types_internal" which take an additional "parsedpos" parameter which will be added to the "poslist" before all others; "parse_generic_specialization_types" calls this new procedure with a dummy argument (which won't be used)
  + extend "parse_generic_parameters" by the parsing of generic constraints which constructs correct defs for the parameters and fills in the new "tgenericconstraintdata" object for each parameter (note: the "constructor" constraint is only parsed for Delphi compatibility and basically means the same as a "class" constraint... (it's a relict of Delphi.NET))
  * adjust "insert_generic_parameter_types" as specializations and generics can no longer be differed by whether the type parameters are of type "undefineddef"
pdecsub.pas, parse_proc_head, consume_generic_interface:
  * adjust call to "generate_specialization"
  + add a new function "check_generic_constraints" which is used from within "generate_specialization" to ensure that the given specialization parameters are compatible with the constraints of the generic parameters
ptype.pas:
  * single_type: adjust call to "generate_specialization"
  * read_named_type, expr_type: adjust call to "generate_specialization"
  + write_persistent_type_info: don't write typeinfo for constraints
pexpr.pas, sub_expr:
  * adjust call to "generate_specialization"
* adjusted ppudump, because of added "tdefoptions.df_genconstraint" value

+ added tests for generic constraints
* modified test for class helper inside a generic which extends a class type parameter
+ added test for record helper inside a generic which extends a record type parameter

git-svn-id: trunk@23158 -
2012-12-16 13:44:58 +00:00

18 lines
158 B
ObjectPascal

{ %FAIL }
program tgenconstraint11;
{$ifdef fpc}
{$mode delphi}
{$endif}
uses
ugenconstraints;
type
TTest4TTestRec = TTest4<TTestRec>;
begin
end.