Browse Source

compiler: fix nested type typecast (issue #0016222)

git-svn-id: trunk@15122 -
paul 15 years ago
parent
commit
c62c487b24
3 changed files with 36 additions and 4 deletions
  1. 1 0
      .gitattributes
  2. 13 4
      compiler/pexpr.pas
  3. 22 0
      tests/webtbs/tw16222.pp

+ 1 - 0
.gitattributes

@@ -10346,6 +10346,7 @@ tests/webtbs/tw16163.pp svneol=native#text/plain
 tests/webtbs/tw1617.pp svneol=native#text/plain
 tests/webtbs/tw16188.pp svneol=native#text/plain
 tests/webtbs/tw1622.pp svneol=native#text/plain
+tests/webtbs/tw16222.pp svneol=native#text/pascal
 tests/webtbs/tw1623.pp svneol=native#text/plain
 tests/webtbs/tw1634.pp svneol=native#text/plain
 tests/webtbs/tw1658.pp svneol=native#text/plain

+ 13 - 4
compiler/pexpr.pas

@@ -1276,10 +1276,19 @@ implementation
                  typesym:
                    begin
                      p1.free;
-                     p1:=ctypenode.create(ttypesym(sym).typedef);
-                     if (is_class(ttypesym(sym).typedef) or is_objcclass(ttypesym(sym).typedef)) and
-                        not(block_type in [bt_type,bt_const_type,bt_var_type]) then
-                       p1:=cloadvmtaddrnode.create(p1);
+                     if try_to_consume(_LKLAMMER) then
+                      begin
+                        p1:=comp_expr(true);
+                        consume(_RKLAMMER);
+                        p1:=ctypeconvnode.create_explicit(p1,ttypesym(sym).typedef);
+                      end
+                     else
+                       begin
+                         p1:=ctypenode.create(ttypesym(sym).typedef);
+                         if (is_class(ttypesym(sym).typedef) or is_objcclass(ttypesym(sym).typedef)) and
+                            not(block_type in [bt_type,bt_const_type,bt_var_type]) then
+                           p1:=cloadvmtaddrnode.create(p1);
+                       end;
                    end;
                  constsym:
                    begin

+ 22 - 0
tests/webtbs/tw16222.pp

@@ -0,0 +1,22 @@
+{ %norun } 
+program tw16222;
+
+{$ifdef fpc}
+  {$mode delphi}
+{$endif}
+
+type
+  TOuterClass = class
+  public
+    type 
+      TInnerClass = class
+      end;
+  end;
+
+function fn(P: Pointer): TOuterClass.TInnerClass;
+begin
+  Result := TOuterClass.TInnerClass(P);
+end;
+
+begin
+end.