소스 검색

* handle inc/dec/pred/succ correctly with type parameters, resolves #23299

git-svn-id: trunk@23248 -
florian 12 년 전
부모
커밋
d140c5b4ee
3개의 변경된 파일37개의 추가작업 그리고 4개의 파일을 삭제
  1. 1 0
      .gitattributes
  2. 10 4
      compiler/ninl.pas
  3. 26 0
      tests/webtbs/tw23299.pp

+ 1 - 0
.gitattributes

@@ -13083,6 +13083,7 @@ tests/webtbs/tw23212.pp svneol=native#text/plain
 tests/webtbs/tw2323.pp svneol=native#text/plain
 tests/webtbs/tw23270.pp svneol=native#text/pascal
 tests/webtbs/tw2328.pp svneol=native#text/plain
+tests/webtbs/tw23299.pp svneol=native#text/pascal
 tests/webtbs/tw2332.pp svneol=native#text/plain
 tests/webtbs/tw23342.pp svneol=native#text/pascal
 tests/webtbs/tw23436.pp svneol=native#text/plain

+ 10 - 4
compiler/ninl.pas

@@ -2698,15 +2698,15 @@ implementation
                 begin
                    set_varstate(left,vs_read,[vsf_must_be_valid]);
                    resultdef:=left.resultdef;
-                   if not is_ordinal(resultdef) then
-                     CGMessage(type_e_ordinal_expr_expected)
-                   else
+                   if is_ordinal(resultdef) or is_typeparam(resultdef) then
                      begin
                        if (resultdef.typ=enumdef) and
                           (tenumdef(resultdef).has_jumps) and
                           not(m_delphi in current_settings.modeswitches) then
                          CGMessage(type_e_succ_and_pred_enums_with_assign_not_possible);
-                     end;
+                     end
+                   else
+                     CGMessage(type_e_ordinal_expr_expected)
                 end;
 
               in_copy_x:
@@ -2771,6 +2771,12 @@ implementation
                                CGMessagePos(tcallparanode(left).right.fileinfo,type_e_ordinal_expr_expected);
                            end;
                         end
+                       { generic type parameter? }
+                       else if is_typeparam(left.resultdef) then
+                         begin
+                           result:=cnothingnode.create;
+                           exit;
+                         end
                        else
                          begin
                            hp:=self;

+ 26 - 0
tests/webtbs/tw23299.pp

@@ -0,0 +1,26 @@
+{$MODE DELPHI}
+
+type
+  TSmallWrapper<TValue> = record
+    Value: TValue;
+  end;
+
+  TWrapper<T> = class
+  strict private
+    class var FSmallWrapper: TSmallWrapper<Integer>;
+  public
+    class procedure Z; static;
+  end;
+
+class procedure TWrapper<T>.Z;
+begin
+  FSmallWrapper.Value := 0;
+  Inc(FSmallWrapper.Value);
+  Dec(FSmallWrapper.Value);
+  FSmallWrapper.Value := Succ(FSmallWrapper.Value);
+  FSmallWrapper.Value := Pred(FSmallWrapper.Value);
+end;
+
+begin
+  TWrapper<Byte>.Z;
+end.