diff --git a/compiler/pdecvar.pas b/compiler/pdecvar.pas index 5e85eef05f..db5feff55e 100644 --- a/compiler/pdecvar.pas +++ b/compiler/pdecvar.pas @@ -1530,25 +1530,25 @@ implementation consume(_SEMICOLON); include(options, vd_class); end; - if vd_class in options then - begin - { add static flag and staticvarsyms } - for i:=0 to sc.count-1 do - begin - fieldvs:=tfieldvarsym(sc[i]); - include(fieldvs.symoptions,sp_static); - { generate the symbol which reserves the space } - static_name:=lower(generate_nested_name(recst,'_'))+'_'+fieldvs.name; - hstaticvs:=tstaticvarsym.create('$_static_'+static_name,vs_value,hdef,[]); - include(hstaticvs.symoptions,sp_internal); - recst.get_unit_symtable.insert(hstaticvs); - insertbssdata(hstaticvs); - { generate the symbol for the access } - sl:=tpropaccesslist.create; - sl.addsym(sl_load,hstaticvs); - recst.insert(tabsolutevarsym.create_ref('$'+static_name,hdef,sl)); - end; - end; + end; + if vd_class in options then + begin + { add static flag and staticvarsyms } + for i:=0 to sc.count-1 do + begin + fieldvs:=tfieldvarsym(sc[i]); + include(fieldvs.symoptions,sp_static); + { generate the symbol which reserves the space } + static_name:=lower(generate_nested_name(recst,'_'))+'_'+fieldvs.name; + hstaticvs:=tstaticvarsym.create('$_static_'+static_name,vs_value,hdef,[]); + include(hstaticvs.symoptions,sp_internal); + recst.get_unit_symtable.insert(hstaticvs); + insertbssdata(hstaticvs); + { generate the symbol for the access } + sl:=tpropaccesslist.create; + sl.addsym(sl_load,hstaticvs); + recst.insert(tabsolutevarsym.create_ref('$'+static_name,hdef,sl)); + end; end; if (visibility=vis_published) and not(is_class(hdef)) then diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 40ec9d7727..f38cf7229f 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -1241,7 +1241,10 @@ implementation if (sp_static in sym.symoptions) then begin static_name:=lower(generate_nested_name(sym.owner,'_'))+'_'+sym.name; - searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable); + if sym.Owner.defowner.typ=objectdef then + searchsym_in_class(tobjectdef(sym.owner.defowner),tobjectdef(sym.owner.defowner),static_name,sym,srsymtable) + else + searchsym_in_record(trecorddef(sym.owner.defowner),static_name,sym,srsymtable); if assigned(sym) then check_hints(sym,sym.symoptions,sym.deprecatedmsg); p1.free; diff --git a/tests/test/terecs3.pp b/tests/test/terecs3.pp index ea401b6689..a85f3c0765 100644 --- a/tests/test/terecs3.pp +++ b/tests/test/terecs3.pp @@ -21,5 +21,7 @@ begin halt(4); if F.Test1(4) <> 5 then halt(5); + if F.F5 <> 6 then + halt(6); WriteLn('ok'); end. \ No newline at end of file diff --git a/tests/test/terecs_u1.pp b/tests/test/terecs_u1.pp index 597b8c5d6e..9e5fa2e081 100644 --- a/tests/test/terecs_u1.pp +++ b/tests/test/terecs_u1.pp @@ -4,7 +4,6 @@ unit terecs_u1; {$mode delphi} interface - type HWND = integer; TFoo = record @@ -20,8 +19,12 @@ type var F3: TBar; F4: Byte; + class var + F5: TBar; function Test(n: TBar): TBar; class function Test1(n: TBar): TBar; + class constructor Create; + class destructor Destroy; end; implementation @@ -36,5 +39,14 @@ begin Result := C + n; end; -end. +class constructor TFoo.Create; +begin + F5 := 6; +end; +class destructor TFoo.Destroy; +begin + WriteLn('TFoo.Destroy'); +end; + +end. \ No newline at end of file