Forráskód Böngészése

* give a proper error when trying to use val() on a boolean (mantis #14777)
* don't allow a boolean or (wide)char to be used as the "error" parameter
for val()

git-svn-id: trunk@14006 -

Jonas Maebe 15 éve
szülő
commit
8d65471fe2
4 módosított fájl, 26 hozzáadás és 2 törlés
  1. 2 0
      .gitattributes
  2. 4 2
      compiler/ninl.pas
  3. 10 0
      tests/webtbf/tw14777.pp
  4. 10 0
      tests/webtbf/tw14777a.pp

+ 2 - 0
.gitattributes

@@ -8750,6 +8750,8 @@ tests/webtbf/tw14650a.pp svneol=native#text/plain
 tests/webtbf/tw1467.pp svneol=native#text/plain
 tests/webtbf/tw14713.pp svneol=native#text/plain
 tests/webtbf/tw14713a.pp svneol=native#text/plain
+tests/webtbf/tw14777.pp svneol=native#text/plain
+tests/webtbf/tw14777a.pp svneol=native#text/plain
 tests/webtbf/tw1483.pp svneol=native#text/plain
 tests/webtbf/tw14849.pp svneol=native#text/plain
 tests/webtbf/tw14929a.pp svneol=native#text/plain

+ 4 - 2
compiler/ninl.pas

@@ -1121,7 +1121,7 @@ implementation
         { check if codepara is valid }
         if assigned(codepara) and
            (
-            (codepara.resultdef.typ <> orddef)
+            not is_integer(codepara.resultdef)
 {$ifndef cpu64bitaddr}
             or is_64bitint(codepara.resultdef)
 {$endif not cpu64bitaddr}
@@ -1132,7 +1132,9 @@ implementation
           end;
 
         { check if dest para is valid }
-        if not(destpara.resultdef.typ in [orddef,floatdef,enumdef]) then
+        if not is_integer(destpara.resultdef) and
+           not is_currency(destpara.resultdef) and
+           not(destpara.resultdef.typ in [floatdef,enumdef]) then
           begin
             CGMessagePos(destpara.fileinfo,type_e_integer_or_real_expr_expected);
             exit;

+ 10 - 0
tests/webtbf/tw14777.pp

@@ -0,0 +1,10 @@
+{ %fail }
+
+var
+  S: String;
+  B: Boolean;
+  E: Word;
+begin
+  S := '0';
+  Val(S, B, E);
+end.

+ 10 - 0
tests/webtbf/tw14777a.pp

@@ -0,0 +1,10 @@
+{ %fail }
+
+var
+  S: String;
+  B: Boolean;
+  E: Word;
+begin
+  S := '0';
+  Val(S, E, B);
+end.