Browse Source

+ parsing of type casts with nested types

git-svn-id: trunk@5335 -
florian 19 years ago
parent
commit
80876932aa
2 changed files with 16 additions and 3 deletions
  1. 13 1
      compiler/pexpr.pas
  2. 3 2
      tests/test/tgeneric10.pp

+ 13 - 1
compiler/pexpr.pas

@@ -2137,7 +2137,19 @@ implementation
                      begin
                        if assigned(getprocvardef) and
                           equal_defs(p1.resultdef,getprocvardef) then
-                         again:=false
+                         begin
+                           { classes can define now types so we've to allow
+                             type casts with these nested types as well }
+                           if (p1.nodetype=typen) and
+                              try_to_consume(_LKLAMMER) then
+                             begin
+                               p1:=comp_expr(true);
+                               consume(_RKLAMMER);
+                               p1:=ctypeconvnode.create_explicit(p1,p1.resultdef);
+                             end
+                           else
+                             again:=false
+                         end
                        else
                          begin
                            if try_to_consume(_LKLAMMER) then

+ 3 - 2
tests/test/tgeneric10.pp

@@ -4,7 +4,7 @@ type
    generic TList<_T>=class(TObject)
    type public
      TCompareFunc = function(const Item1, Item2: _T): Integer;
-   var public 
+   var public
      data : _T;
      compare : TCompareFunc;
      procedure Add(item: _T);
@@ -17,7 +17,7 @@ begin
     halt(1);
 end;
 
-function CompareInt(Item1, Item2: Integer): Integer;
+function CompareInt(const Item1, Item2: Integer): Integer;
 begin
   Result := Item2 - Item1;
 end;
@@ -33,4 +33,5 @@ begin
   ilist := TMyIntList.Create;
   ilist.compare := ilist.TCompareFunc(@CompareInt);
   ilist.add(someInt);
+  writeln('ok');
 end.