From c62c487b24158e4aa09c8af4055c58a3c3c1a016 Mon Sep 17 00:00:00 2001 From: paul Date: Fri, 9 Apr 2010 17:10:52 +0000 Subject: [PATCH] compiler: fix nested type typecast (issue #0016222) git-svn-id: trunk@15122 - --- .gitattributes | 1 + compiler/pexpr.pas | 17 +++++++++++++---- tests/webtbs/tw16222.pp | 22 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) create mode 100644 tests/webtbs/tw16222.pp diff --git a/.gitattributes b/.gitattributes index afb384642c..7bec508b1a 100644 --- a/.gitattributes +++ b/.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 diff --git a/compiler/pexpr.pas b/compiler/pexpr.pas index 28f23404c9..ef482ff6c1 100644 --- a/compiler/pexpr.pas +++ b/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 diff --git a/tests/webtbs/tw16222.pp b/tests/webtbs/tw16222.pp new file mode 100644 index 0000000000..a45b545063 --- /dev/null +++ b/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. \ No newline at end of file