Bläddra i källkod

pdecl.pas, readconstant: If we are parsing a constant declaration in a generic and we encounter an intrinsic then this intrinsic is left as is (thus the node p returned by comp_expr will be a inlinen instead of an expected ordconstn, stringconstn, etc.). Nevertheless we need to create a symbol for the constant (which isn't done otherwise). In the case of SizeOf a constant "0" will be created. This fixes Mantis #21593.

git-svn-id: trunk@21498 -
svenbarth 13 år sedan
förälder
incheckning
aa0f1bdf26
5 ändrade filer med 81 tillägg och 2 borttagningar
  1. 3 0
      .gitattributes
  2. 20 2
      compiler/pdecl.pas
  3. 19 0
      tests/webtbs/tw21593a.pp
  4. 20 0
      tests/webtbs/tw21593b.pp
  5. 19 0
      tests/webtbs/tw21593c.pp

+ 3 - 0
.gitattributes

@@ -12603,6 +12603,9 @@ tests/webtbs/tw2159.pp svneol=native#text/plain
 tests/webtbs/tw21592.pp svneol=native#text/pascal
 tests/webtbs/tw21592b.pp svneol=native#text/pascal
 tests/webtbs/tw21593.pp svneol=native#text/pascal
+tests/webtbs/tw21593a.pp svneol=native#text/pascal
+tests/webtbs/tw21593b.pp svneol=native#text/pascal
+tests/webtbs/tw21593c.pp svneol=native#text/pascal
 tests/webtbs/tw2163.pp svneol=native#text/plain
 tests/webtbs/tw21654.pp svneol=native#text/pascal
 tests/webtbs/tw21674.pp svneol=native#text/pascal

+ 20 - 2
compiler/pdecl.pas

@@ -153,9 +153,27 @@ implementation
                else
                 Message(parser_e_illegal_expression);
              end;
+           inlinen:
+             begin
+               { this situation only happens if a intrinsic is parsed that has a
+                 generic type as its argument. As we don't know certain
+                 information about the final type yet, we need to use safe
+                 values (mostly 0) }
+               if not parse_generic then
+                 Message(parser_e_illegal_expression);
+               case tinlinenode(p).inlinenumber of
+                 in_sizeof_x,
+                 in_bitsizeof_x:
+                   begin
+                     hp:=tconstsym.create_ord(orgname,constord,0,p.resultdef);
+                   end;
+                 { add other cases here if necessary }
+                 else
+                   Message(parser_e_illegal_expression);
+               end;
+             end;
            else
-             if not(parse_generic) then
-               Message(parser_e_illegal_expression);
+             Message(parser_e_illegal_expression);
         end;
         current_tokenpos:=storetokenpos;
         p.free;

+ 19 - 0
tests/webtbs/tw21593a.pp

@@ -0,0 +1,19 @@
+program tw21593a;
+
+{$MODE DELPHI}
+
+type
+  TWrapper<T> = record
+    class procedure Test; static;
+  end;
+
+class procedure TWrapper<T>.Test;
+const
+  Size = SizeOf(T);  { Error: Illegal expression }
+begin
+  Writeln(Size);
+end;
+
+begin
+  TWrapper<Byte>.Test;
+end.

+ 20 - 0
tests/webtbs/tw21593b.pp

@@ -0,0 +1,20 @@
+program tw21593b;
+
+{$MODE DELPHI}
+
+type
+  TWrapper<T> = record
+  strict private
+    const Size = SizeOf(T);  { Error: Illegal expression }
+  public
+    class procedure Test; static;
+  end;
+
+class procedure TWrapper<T>.Test;
+begin
+  Writeln(Size);
+end;
+
+begin
+  TWrapper<Byte>.Test;
+end.

+ 19 - 0
tests/webtbs/tw21593c.pp

@@ -0,0 +1,19 @@
+program tw21593c;
+
+{$MODE DELPHI}
+
+type
+  TWrapper<T> = record
+    class procedure Test; static;
+  end;
+
+class procedure TWrapper<T>.Test;
+var
+  size: SizeInt = SizeOf(T);  { Error: Illegal expression }
+begin
+  Writeln(size);
+end;
+
+begin
+  TWrapper<Byte>.Test;
+end.