diff --git a/.gitattributes b/.gitattributes index a04b0a38f0..03f8948ec3 100644 --- a/.gitattributes +++ b/.gitattributes @@ -13477,6 +13477,7 @@ tests/webtbs/tw2481.pp svneol=native#text/plain tests/webtbs/tw2483.pp svneol=native#text/plain tests/webtbs/tw24848.pp svneol=native#text/pascal tests/webtbs/tw24863.pp svneol=native#text/plain +tests/webtbs/tw24871.pp svneol=native#text/pascal tests/webtbs/tw2492.pp svneol=native#text/plain tests/webtbs/tw2494.pp svneol=native#text/plain tests/webtbs/tw2503.pp svneol=native#text/plain diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index a403c0a066..b70e754778 100644 --- a/compiler/pexpr.pas +++ b/compiler/pexpr.pas @@ -2788,6 +2788,22 @@ implementation factor_read_set:=buildp; end; + function can_load_self_node: boolean; + var + procinfo: tprocinfo; + begin + result:=false; + if (block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) or + not assigned(current_structdef) or + not assigned(current_procinfo) then + exit; + procinfo:=current_procinfo; + if procinfo.procdef.parast.symtablelevelnormal_function_level) do + procinfo:=procinfo.parent; + result:=not procinfo.procdef.no_self_node; + end; {--------------------------------------------- Factor (Main) @@ -2822,9 +2838,7 @@ implementation begin again:=true; { Handle references to self } - if (idtoken=_SELF) and - not(block_type in [bt_const,bt_type,bt_const_type,bt_var_type]) and - assigned(current_structdef) then + if (idtoken=_SELF) and can_load_self_node then begin p1:=load_self_node; consume(_ID); diff --git a/compiler/procinfo.pas b/compiler/procinfo.pas index a697bdad20..9811745128 100644 --- a/compiler/procinfo.pas +++ b/compiler/procinfo.pas @@ -52,6 +52,9 @@ unit procinfo; { This object gives information on the current routine being compiled. } + + { tprocinfo } + tprocinfo = class(tlinkedlistitem) private { list to store the procinfo's of the nested procedures } diff --git a/tests/webtbs/tw24871.pp b/tests/webtbs/tw24871.pp new file mode 100644 index 0000000000..be5c460321 --- /dev/null +++ b/tests/webtbs/tw24871.pp @@ -0,0 +1,57 @@ +program tw24871; + +{$mode delphi} +{$APPTYPE CONSOLE} + +type + TRec = record + class procedure Foo(Self: TObject); static; + end; + + { TClass } + + TClass = class + class procedure Foo(Self: TObject); static; + end; + +{ TRec } + +class procedure TRec.Foo(Self: TObject); + + procedure Foo1; + + procedure Foo2; + begin + Self.ClassName; + end; + + begin + Self.ClassName; + end; + +begin + Self.ClassName; +end; + +{ TClass } + +class procedure TClass.Foo(Self: TObject); + + procedure Foo1; + + procedure Foo2; + begin + Self.ClassName; + end; + + begin + Self.ClassName; + end; + +begin + Self.ClassName; +end; + +begin +end. +