2
0
Эх сурвалжийг харах

* fixed calling static TP-style object methods from within other methods
(mantis #16954)

git-svn-id: trunk@15598 -

Jonas Maebe 15 жил өмнө
parent
commit
b18a4617bb

+ 1 - 0
.gitattributes

@@ -10546,6 +10546,7 @@ tests/webtbs/tw16874.pp svneol=native#text/plain
 tests/webtbs/tw16901.pp svneol=native#text/plain
 tests/webtbs/tw16901.pp svneol=native#text/plain
 tests/webtbs/tw16949a.pp svneol=native#text/plain
 tests/webtbs/tw16949a.pp svneol=native#text/plain
 tests/webtbs/tw16949b.pp svneol=native#text/plain
 tests/webtbs/tw16949b.pp svneol=native#text/plain
+tests/webtbs/tw16954.pp svneol=native#text/plain
 tests/webtbs/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1696.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1699.pp svneol=native#text/plain
 tests/webtbs/tw1709.pp svneol=native#text/plain
 tests/webtbs/tw1709.pp svneol=native#text/plain

+ 16 - 20
compiler/pexpr.pas

@@ -1508,29 +1508,25 @@ implementation
                            is_object(hdef) then
                            is_object(hdef) then
                          begin
                          begin
                            consume(_POINT);
                            consume(_POINT);
+                           { handles calling methods declared in parent objects
+                             using "parentobject.methodname()" }
                            if assigned(current_objectdef) and
                            if assigned(current_objectdef) and
-                              not(getaddr) then
-                            begin
-                              if current_objectdef.is_related(tobjectdef(hdef)) then
-                               begin
-                                 p1:=ctypenode.create(hdef);
-                                 { search also in inherited methods }
-                                 searchsym_in_class(tobjectdef(hdef),current_objectdef,pattern,srsym,srsymtable);
-                                 if assigned(srsym) then
-                                   check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
-                                 consume(_ID);
-                                 do_member_read(tobjectdef(hdef),false,srsym,p1,again,[]);
-                               end
-                              else
-                               begin
-                                 Message(parser_e_no_super_class);
-                                 again:=false;
-                               end;
-                            end
+                              not(getaddr) and
+                              current_objectdef.is_related(tobjectdef(hdef)) then
+                             begin
+                               p1:=ctypenode.create(hdef);
+                               { search also in inherited methods }
+                               searchsym_in_class(tobjectdef(hdef),current_objectdef,pattern,srsym,srsymtable);
+                               if assigned(srsym) then
+                                 check_hints(srsym,srsym.symoptions,srsym.deprecatedmsg);
+                               consume(_ID);
+                               do_member_read(tobjectdef(hdef),false,srsym,p1,again,[]);
+                             end
                            else
                            else
                             begin
                             begin
-                              { allows @TObject.Load }
-                              { also allows static methods and variables }
+                              { handles:
+                                  * @TObject.Load
+                                  * static methods and variables }
                               p1:=ctypenode.create(hdef);
                               p1:=ctypenode.create(hdef);
                               { TP allows also @TMenu.Load if Load is only }
                               { TP allows also @TMenu.Load if Load is only }
                               { defined in an anchestor class              }
                               { defined in an anchestor class              }

+ 40 - 0
tests/webtbs/tw16954.pp

@@ -0,0 +1,40 @@
+program project_static2;
+type
+   Etyp=(t1,t2,t3);
+
+type
+   ProxyObject=object
+     function IsInSubrange(const typ:Etyp):boolean;static;
+   end;
+
+   RealObject=object
+     mytyp:Etyp;
+     function IsInSubrange:boolean;
+   end;
+
+function RealObject.IsInSubrange: boolean;
+begin
+   IsInSubrange:=ProxyObject.IsInSubrange(mytyp);  
+   // ^-- Error: Class isn't a parent class of the current class
+   // and AV of compiler
+end;
+
+function ProxyObject.IsInSubrange(const typ: Etyp): boolean;
+begin
+   IsInSubrange:=typ<=t2;
+end;
+
+var o:RealObject;
+
+begin
+  if ProxyObject.IsInSubrange(t3) then
+    halt(1);
+  if not ProxyObject.IsInSubrange(t2) then
+    halt(2);
+  o.mytyp:=t3;
+  if o.isInSubRange then
+    halt(3);
+  o.mytyp:=t1;
+  if not o.isInSubRange then
+    halt(4);
+end.