Parcourir la source

* Allow for "record constraint" in Delphi mode more types like: ordinal, float, classical objects, enumerations (instead of just record). Delphi compatibility. Fix for mantis #24073.

git-svn-id: trunk@35739 -
maciej-izak il y a 8 ans
Parent
commit
e4565378db
3 fichiers modifiés avec 47 ajouts et 1 suppressions
  1. 1 0
      .gitattributes
  2. 16 1
      compiler/pgenutil.pas
  3. 30 0
      tests/webtbs/tw24073.pp

+ 1 - 0
.gitattributes

@@ -14966,6 +14966,7 @@ tests/webtbs/tw23980.pp svneol=native#text/pascal
 tests/webtbs/tw24007.pp svneol=native#text/plain
 tests/webtbs/tw24071.pp svneol=native#text/pascal
 tests/webtbs/tw24072.pp svneol=native#text/pascal
+tests/webtbs/tw24073.pp svneol=native#text/pascal
 tests/webtbs/tw2409.pp svneol=native#text/plain
 tests/webtbs/tw24129.pp svneol=native#text/pascal
 tests/webtbs/tw24131.pp svneol=native#text/plain

+ 16 - 1
compiler/pgenutil.pas

@@ -144,7 +144,22 @@ uses
               begin
                 case formaldef.typ of
                   recorddef:
-                    MessagePos(filepos,type_e_record_type_expected);
+                    { delphi has own fantasy about record constraint
+                      (almost non-nullable/non-nilable value type) }
+                    if m_delphi in current_settings.modeswitches then
+                      case paradef.typ of
+                        floatdef,enumdef,orddef:
+                          continue;
+                        objectdef:
+                          if tobjectdef(paradef).objecttype=odt_object then
+                            continue
+                          else
+                            MessagePos(filepos,type_e_record_type_expected);
+                        else
+                          MessagePos(filepos,type_e_record_type_expected);
+                      end
+                    else
+                      MessagePos(filepos,type_e_record_type_expected);
                   objectdef:
                     case tobjectdef(formaldef).objecttype of
                       odt_class,

+ 30 - 0
tests/webtbs/tw24073.pp

@@ -0,0 +1,30 @@
+{ %NORUN }
+
+{$MODE DELPHI}
+
+type
+  TA<T: record> = record
+  end;
+
+  TUnamanagedRec = record
+    x: integer;
+  end;
+
+  TManagedRec = record
+    s: string;
+  end;
+
+  TEnum = (e1, e2, e3);
+
+  TObj = object
+  end;
+
+var
+  a: TA<TUnamanagedRec>;
+  b: TA<TManagedRec>;
+  d: TA<Single>;
+  e: TA<Integer>;
+  f: TA<TEnum>;
+  g: TA<TObj>;
+begin
+end.