fpc/tests/test/tgeneric95.pp
svenbarth 53ea24a0b1 Correctly specialize generics if locally declared types are used (e.g. two procedures could both define a different "TRec" type which is used to specialize a generic inside the procedures).
symtype.pas, tdef:
  + add method "fullownerhierarchyname" which allows to retrieve the owner hierarchy name including procedure/function/method names
  + add method "fulltypename" which uses "fullownerhierarchyname" to return a full type name
symdef.pas, tstoreddef:
  * implement "fullownerhierarchyname" (including caching of the result)
pgenutil.pas, parse_generic_specialization_types_internal:
  * use "tdef.fulltypename" instead of "tdef.typename" to have unique values for each parsed type and thus for the specialization itself

+ tests

git-svn-id: trunk@25175 -
2013-07-26 09:02:24 +00:00

41 lines
641 B
ObjectPascal

program tgeneric95;
{$mode objfpc}
type
generic TTest<T> = record
f: T;
end;
function Test(aArg: Integer): Integer;
type
TTest_Word = specialize TTest<Word>;
var
t: TTest_Word;
begin
Result := SizeOf(t.f);
end;
function Test(aArg: String): Integer;
type
TTest_String = specialize TTest<String>;
var
t: TTest_String;
begin
Result := SizeOf(t.f);
end;
procedure DoError(const aMessage: String);
begin
Writeln(aMessage);
ExitCode := 1;
Halt;
end;
begin
if Test(42) <> SizeOf(Word) then
DoError('Unexpected size of field');
if Test('Test') <> SizeOf(String) then
DoError('Unexpe size of field');
end.