diff --git a/.gitattributes b/.gitattributes index bce897a0fa..719c3417b1 100644 --- a/.gitattributes +++ b/.gitattributes @@ -9427,6 +9427,7 @@ tests/test/tgeneric30.pp svneol=native#text/pascal tests/test/tgeneric31.pp svneol=native#text/pascal tests/test/tgeneric32.pp svneol=native#text/pascal tests/test/tgeneric33.pp svneol=native#text/pascal +tests/test/tgeneric34.pp svneol=native#text/pascal tests/test/tgeneric4.pp svneol=native#text/plain tests/test/tgeneric5.pp svneol=native#text/plain tests/test/tgeneric6.pp svneol=native#text/plain diff --git a/compiler/psub.pas b/compiler/psub.pas index f42e8fbe9b..a03d8f0003 100644 --- a/compiler/psub.pas +++ b/compiler/psub.pas @@ -1984,20 +1984,20 @@ implementation oldsymtablestack : tsymtablestack; pu : tused_unit; hmodule : tmodule; - specobj : tobjectdef; + specobj : tabstractrecorddef; begin if not((tsym(p).typ=typesym) and (ttypesym(p).typedef.typesym=tsym(p)) and - (ttypesym(p).typedef.typ=objectdef) and + (ttypesym(p).typedef.typ in [objectdef,recorddef]) and (df_specialization in ttypesym(p).typedef.defoptions) ) then exit; { Setup symtablestack a definition time } - specobj:=tobjectdef(ttypesym(p).typedef); + specobj:=tabstractrecorddef(ttypesym(p).typedef); oldsymtablestack:=symtablestack; symtablestack:=tsymtablestack.create; - if not assigned(tobjectdef(ttypesym(p).typedef).genericdef) then + if not assigned(specobj.genericdef) then internalerror(200705151); hmodule:=find_module_from_symtable(specobj.genericdef.owner); if hmodule=nil then @@ -2016,7 +2016,7 @@ implementation symtablestack.push(hmodule.localsymtable); { procedure definitions for classes or objects } - if is_class_or_object(specobj) then + if is_class_or_object(specobj) or is_record(specobj) then begin for i:=0 to specobj.symtable.DefList.Count-1 do begin diff --git a/tests/test/tgeneric34.pp b/tests/test/tgeneric34.pp new file mode 100644 index 0000000000..999c52087a --- /dev/null +++ b/tests/test/tgeneric34.pp @@ -0,0 +1,21 @@ +program tgeneric34; + +{$mode delphi} + +type + TFoo = record + function DoSomething(Arg: T): T; + end; + +function TFoo.DoSomething(Arg: T): T; +begin + Result := Arg; +end; + +var + FooInt: TFoo; +begin + if FooInt.DoSomething(1) <> 1 then + halt(1); +end. +