Browse Source

* don't crash when searching for a type helper in an anonymous array (or
other non-record/objectdef-based) type (mantis #25504)

git-svn-id: trunk@26459 -

Jonas Maebe 11 năm trước cách đây
mục cha
commit
5fc4af09dd
3 tập tin đã thay đổi với 49 bổ sung2 xóa
  1. 1 0
      .gitattributes
  2. 4 2
      compiler/symtable.pas
  3. 44 0
      tests/webtbf/tw25504.pp

+ 1 - 0
.gitattributes

@@ -12614,6 +12614,7 @@ tests/webtbf/tw2478.pp svneol=native#text/plain
 tests/webtbf/tw25029.pp svneol=native#text/pascal
 tests/webtbf/tw25215.pp svneol=native#text/pascal
 tests/webtbf/tw25318.pp svneol=native#text/pascal
+tests/webtbf/tw25504.pp svneol=native#text/plain
 tests/webtbf/tw2562.pp svneol=native#text/plain
 tests/webtbf/tw2657.pp svneol=native#text/plain
 tests/webtbf/tw2670.pp svneol=native#text/plain

+ 4 - 2
compiler/symtable.pas

@@ -3139,11 +3139,13 @@ implementation
         if current_module.extendeddefs.count=0 then
           exit;
         { no helpers for anonymous types }
-        if (pd.typ in [recorddef,objectdef]) and
+        if ((pd.typ in [recorddef,objectdef]) and
             (
               not assigned(tabstractrecorddef(pd).objrealname) or
               (tabstractrecorddef(pd).objrealname^='')
-            ) then
+            )
+           ) or
+           not assigned(pd.typesym) then
           exit;
         { if pd is defined inside a procedure we must not use make_mangledname
           (as a helper may not be defined in a procedure this is no problem...)}

+ 44 - 0
tests/webtbf/tw25504.pp

@@ -0,0 +1,44 @@
+{ %fail }
+program test;
+
+{$MODE DELPHI}
+
+{ Commenting the next block of code causes compiler to properly show error message in "Data.HelloWorld".
+  Otherwise, it throws error:
+    Fatal: Compilation aborted
+    An unhandled exception occurred at $00437C5E:
+    EAccessViolation: Access violation
+      $00437C5E
+}
+type
+// {
+  TDateTimeStamp = record
+    Value: Int64;
+  end;
+
+const
+  InvalidDateTimeStampValue = Low(Int64);
+
+type
+  TDateTimeStampHelper = record helper for TDateTimeStamp
+    const Invalid: TDateTimeStamp = (Value: InvalidDateTimeStampValue);
+  end;
+// }
+
+  TSomeOtherClass = class
+  end;
+
+  TSomeClass = class
+  private
+    Data: array of TSomeOtherClass;
+  public
+    procedure Test;
+  end;
+
+procedure TSomeClass.Test;
+begin
+  Data.HelloWorld;
+end;
+
+begin
+end.