Browse Source

* handle generic parameters in Ord()
+ added test

git-svn-id: trunk@45232 -

svenbarth 5 years ago
parent
commit
3d2945726a
3 changed files with 44 additions and 1 deletions
  1. 1 0
      .gitattributes
  2. 10 1
      compiler/ninl.pas
  3. 33 0
      tests/tbs/tb0672.pp

+ 1 - 0
.gitattributes

@@ -13275,6 +13275,7 @@ tests/tbs/tb0668b.pp svneol=native#text/pascal
 tests/tbs/tb0669.pp svneol=native#text/pascal
 tests/tbs/tb0670.pp svneol=native#text/pascal
 tests/tbs/tb0671.pp svneol=native#text/pascal
+tests/tbs/tb0672.pp svneol=native#text/pascal
 tests/tbs/ub0060.pp svneol=native#text/plain
 tests/tbs/ub0069.pp svneol=native#text/plain
 tests/tbs/ub0119.pp svneol=native#text/plain

+ 10 - 1
compiler/ninl.pas

@@ -2431,6 +2431,14 @@ implementation
                         result:=ctypeconvnode.create_internal(left,s32inttype);
                         left:=nil;
                       end;
+                    undefineddef :
+                      begin
+                        { we just create a constant 0 here, that's marked as a
+                          parameter }
+                        result:=cordconstnode.create(0,s32inttype,false);
+                        include(result.flags,nf_generic_para);
+                        left:=nil;
+                      end;
                     pointerdef :
                       begin
                         if m_mac in current_settings.modeswitches then
@@ -3017,7 +3025,8 @@ implementation
                    set_varstate(left,vs_read,[vsf_must_be_valid]);
                    case left.resultdef.typ of
                      orddef,
-                     enumdef :
+                     enumdef,
+                     undefineddef :
                        ;
                      pointerdef :
                        begin

+ 33 - 0
tests/tbs/tb0672.pp

@@ -0,0 +1,33 @@
+program tb0672;
+
+{$mode objfpc}
+
+type
+  generic TTest<T> = class
+    class function Test(aArg: T): LongInt;
+  end;
+
+class function TTest.Test(aArg: T): LongInt;
+begin
+  Result := Ord(aArg);
+end;
+
+type
+  TEnum = (teOne, teTwo, teThree);
+
+  TTestBoolean = specialize TTest<Boolean>;
+  TTestChar = specialize TTest<Char>;
+  TTestWideChar = specialize TTest<WideChar>;
+  TTestEnum = specialize TTest<TEnum>;
+
+begin
+  if TTestBoolean.Test(True) <> Ord(True) then
+    Halt(1);
+  if TTestChar.Test(#42) <> Ord(#42) then
+    Halt(2);
+  if TTestWideChar.Test(#1234) <> Ord(#1234) then
+    Halt(3);
+  if TTestEnum.Test(teTwo) <> Ord(teTwo) then
+    Halt(4);
+  Writeln('ok');
+end.