瀏覽代碼

* let type conversion nodes handle type checking for if/while/repeat
conditions, so that used-defined implicit boolean type conversions are
supported (patch by Peter-Jan Roes, mantis #23568)

git-svn-id: trunk@23525 -

Jonas Maebe 12 年之前
父節點
當前提交
dc7760bda0
共有 3 個文件被更改,包括 63 次插入12 次删除
  1. 1 0
      .gitattributes
  2. 3 12
      compiler/nflw.pas
  3. 59 0
      tests/webtbs/tw23568.pp

+ 1 - 0
.gitattributes

@@ -13154,6 +13154,7 @@ tests/webtbs/tw23447.pp svneol=native#text/pascal
 tests/webtbs/tw23486.pp svneol=native#text/pascal
 tests/webtbs/tw23486.pp svneol=native#text/pascal
 tests/webtbs/tw23503.pp svneol=native#text/pascal
 tests/webtbs/tw23503.pp svneol=native#text/pascal
 tests/webtbs/tw2351.pp svneol=native#text/plain
 tests/webtbs/tw2351.pp svneol=native#text/plain
+tests/webtbs/tw23568.pp -text svneol=native#text/plain
 tests/webtbs/tw2363.pp svneol=native#text/plain
 tests/webtbs/tw2363.pp svneol=native#text/plain
 tests/webtbs/tw23744.pp svneol=native#text/plain
 tests/webtbs/tw23744.pp svneol=native#text/plain
 tests/webtbs/tw2377.pp svneol=native#text/plain
 tests/webtbs/tw2377.pp svneol=native#text/plain

+ 3 - 12
compiler/nflw.pas

@@ -1072,12 +1072,7 @@ implementation
 
 
          if not(is_boolean(left.resultdef)) and
          if not(is_boolean(left.resultdef)) and
            not(is_typeparam(left.resultdef)) then
            not(is_typeparam(left.resultdef)) then
-           begin
-             if left.resultdef.typ=variantdef then
-               inserttypeconv(left,pasbool8type)
-             else
-               CGMessage1(type_e_boolean_expr_expected,left.resultdef.typename);
-           end;
+             inserttypeconv(left,pasbool8type);
 
 
          { Give warnings for code that will never be executed for
          { Give warnings for code that will never be executed for
            while false do }
            while false do }
@@ -1385,12 +1380,8 @@ implementation
 
 
          if not(is_boolean(left.resultdef)) and
          if not(is_boolean(left.resultdef)) and
            not(is_typeparam(left.resultdef)) then
            not(is_typeparam(left.resultdef)) then
-           begin
-             if left.resultdef.typ=variantdef then
-               inserttypeconv(left,pasbool8type)
-             else
-               Message1(type_e_boolean_expr_expected,left.resultdef.typename);
-           end;
+             inserttypeconv(left,pasbool8type);
+
          result:=internalsimplify(true);
          result:=internalsimplify(true);
       end;
       end;
 
 

+ 59 - 0
tests/webtbs/tw23568.pp

@@ -0,0 +1,59 @@
+program tw23568;
+
+{$MODE DELPHI}
+
+type
+  TInteger32Boolean = record
+  public
+    Value: Integer;
+    
+    class operator Implicit(const Operand: TInteger32Boolean): Boolean;
+  end;
+  
+{ TInteger32Boolean }
+
+class operator TInteger32Boolean.Implicit(const Operand: TInteger32Boolean): Boolean;
+begin
+  Result := Operand.Value <> 0;
+  WriteLn('In TInteger32Boolean.Implicit()');
+end;
+
+var
+  Value:        TInteger32Boolean;
+  Intermediate: Boolean;
+
+begin
+  // Assign True to TInteger32Boolean
+  Value.Value := 1;
+  
+  // If statement using intermediate assignment through Intermediate
+  Intermediate := Value;
+
+  if Intermediate then
+    WriteLn('True')
+  else
+    halt(1);
+    
+  // If statement should perform implicit type conversion from TInteger32Boolean to Boolean
+  if Value then
+    WriteLn('True')
+  else
+    halt(2);
+    
+  // While statement should perform implicit type conversion as well
+  while Value do
+  begin
+    if Value.Value=0 then
+      halt(3);
+    Value.Value := 0;
+    WriteLn('While');
+  end;
+  
+  // Repeat until statement should perform implicit type conversion as well
+  repeat 
+    if Value.Value=1 then
+      halt(4);
+    Value.Value := 1;
+    WriteLn('Repeat until');
+  until Value;
+end.