Selaa lähdekoodia

* fixed "inherited some_property" constructs for getters/setters
(mantis #10927)
* extended the tb0259 test a bit (tests similar constructs in
case there is no getter/setter)

git-svn-id: trunk@10456 -

Jonas Maebe 17 vuotta sitten
vanhempi
commit
005bdc1af4
4 muutettua tiedostoa jossa 103 lisäystä ja 4 poistoa
  1. 1 0
      .gitattributes
  2. 26 2
      compiler/pexpr.pas
  3. 19 2
      tests/tbs/tb0259.pp
  4. 57 0
      tests/webtbs/tw10927.pp

+ 1 - 0
.gitattributes

@@ -8008,6 +8008,7 @@ tests/webtbs/tw10897.pp svneol=native#text/plain
 tests/webtbs/tw1090.pp svneol=native#text/plain
 tests/webtbs/tw1092.pp svneol=native#text/plain
 tests/webtbs/tw10920.pp svneol=native#text/plain
+tests/webtbs/tw10927.pp svneol=native#text/plain
 tests/webtbs/tw10931.pp svneol=native#text/plain
 tests/webtbs/tw1096.pp svneol=native#text/plain
 tests/webtbs/tw10966.pp svneol=native#text/plain

+ 26 - 2
compiler/pexpr.pas

@@ -1062,6 +1062,21 @@ implementation
                      fieldvarsym :
                        begin
                          { generate access code }
+
+                         { for fieldvars, having a typenode is wrong:   }
+                         { fields cannot be overridden/hidden in child  }
+                         { classes. However, we always have to pass the }
+                         { typenode to handle_propertysym because the   }
+                         { parent doesn't know yet to what the property }
+                         { will resolve (and in case of procsyms, we do }
+                         { need the type node in case of                }
+                         { "inherited property_with_getter/setter"      }
+                         if (assigned(p1)) and
+                            (p1.nodetype = typen) then
+                           begin
+                             p1.free;
+                             p1:=nil;
+                           end;
                          propaccesslist_to_node(p1,st,propaccesslist);
                          include(p1.flags,nf_isproperty);
                          consume(_ASSIGNMENT);
@@ -1090,6 +1105,15 @@ implementation
                      fieldvarsym :
                        begin
                           { generate access code }
+
+                          { for fieldvars, having a typenode is wrong:   }
+                          { see comments above for write access          }
+                          if (assigned(p1)) and
+                             (p1.nodetype = typen) then
+                            begin
+                              p1.free;
+                              p1:=nil;
+                            end;
                           propaccesslist_to_node(p1,st,propaccesslist);
                           include(p1.flags,nf_isproperty);
                        end;
@@ -2234,14 +2258,14 @@ implementation
                        not from self }
                      if srsym.typ in [procsym,propertysym] then
                       begin
+                        hdef:=hclassdef;
                         if (srsym.typ = procsym) then
                           begin
-                            hdef:=hclassdef;
                             if (po_classmethod in current_procinfo.procdef.procoptions) or
                                (po_staticmethod in current_procinfo.procdef.procoptions) then
                               hdef:=tclassrefdef.create(hdef);
-                            p1:=ctypenode.create(hdef);
                           end;
+                        p1:=ctypenode.create(hdef);
                       end
                      else
                       begin

+ 19 - 2
tests/tbs/tb0259.pp

@@ -5,18 +5,35 @@
 type
   c1=class
     Ffont : longint;
-    property Font:longint read Ffont;
+    property Font:longint read Ffont write Ffont;
   end;
 
   c2=class(c1)
     function GetFont:longint;
+    procedure setfont(l: longint);
   end;
 
 function c2.GetFont:longint;
 begin
-  result:=Font;
   result:=inherited Font;
 end;
 
+
+procedure c2.SetFont(l: longint);
+begin
+  inherited font := l;  
+end;
+
+var
+  c: c2;
 begin
+  c:=c2.create;
+  c.ffont:=5;
+  if c.getfont<>5 then
+    halt(1);
+  c.setfont(10);
+  if c.getfont<>10 then
+    halt(2);
+  if c.ffont<>10 then
+    halt(3);
 end.

+ 57 - 0
tests/webtbs/tw10927.pp

@@ -0,0 +1,57 @@
+program project1;
+
+{$mode objfpc}{$H+}
+
+type
+
+  { TOrgObject }
+
+  TOriginal=class
+  protected
+    procedure SetReadOnly(const AValue: boolean); virtual;
+  public
+    property readonly:boolean write SetReadOnly;
+  end;
+
+  { TDerived }
+
+  TDerived=class(TOriginal)
+  protected
+    procedure SetReadOnly(const AValue: boolean); override;
+  end;
+
+var
+ count1, count2: longint;
+
+{ TDerived }
+
+procedure TDerived.SetReadOnly(const AValue: boolean);
+begin
+  if (count2>0) then
+    halt(1);
+  inc(count2);
+  WriteLn('TDerived.SetReadOnly');
+  inherited;
+  inherited ReadOnly := AValue;
+end;
+
+{ TOrgObject }
+
+procedure TOriginal.SetReadOnly(const AValue: boolean);
+begin
+  if (count1>1) then
+    halt(2);
+  inc(count1);
+  WriteLn('TOriginal.SetReadOnly');
+end;
+
+var
+  D: TDerived;
+begin
+  D := TDerived.Create;
+  D.ReadOnly := True;
+  D.Free;
+  if (count1<>2) or
+     (count2<>1) then
+    halt(3);
+end.