Browse Source

* convert booleans to the actual array index type (mantis #15364)

git-svn-id: trunk@14445 -
Jonas Maebe 15 years ago
parent
commit
10cfba3b28
3 changed files with 22 additions and 2 deletions
  1. 1 0
      .gitattributes
  2. 5 2
      compiler/nmem.pas
  3. 16 0
      tests/webtbs/tw15364.pp

+ 1 - 0
.gitattributes

@@ -10139,6 +10139,7 @@ tests/webtbs/tw15293.pp svneol=native#text/plain
 tests/webtbs/tw15293a.pp svneol=native#text/plain
 tests/webtbs/tw15304.pp svneol=native#text/plain
 tests/webtbs/tw1532.pp svneol=native#text/plain
+tests/webtbs/tw15364.pp svneol=native#text/plain
 tests/webtbs/tw1539.pp svneol=native#text/plain
 tests/webtbs/tw1567.pp svneol=native#text/plain
 tests/webtbs/tw1573.pp svneol=native#text/plain

+ 5 - 2
compiler/nmem.pas

@@ -733,9 +733,9 @@ implementation
           exit;
 
          { maybe type conversion for the index value, but
-           do not convert enums,booleans,char
+           do not convert enums, char (why not? (JM))
            and do not convert range nodes }
-         if (right.nodetype<>rangen) and (is_integer(right.resultdef) or (left.resultdef.typ<>arraydef)) then
+         if (right.nodetype<>rangen) and (is_integer(right.resultdef) or is_boolean(right.resultdef) or (left.resultdef.typ<>arraydef)) then
            case left.resultdef.typ of
              arraydef:
                if ado_isvariant in Tarraydef(left.resultdef).arrayoptions then
@@ -748,6 +748,9 @@ implementation
                  {Arrays without a high bound (dynamic arrays, open arrays) are zero based,
                   convert indexes into these arrays to aword.}
                  inserttypeconv(right,uinttype)
+               { convert between pasbool and cbool if necessary }
+               else if is_boolean(right.resultdef) then
+                 inserttypeconv(right,tarraydef(left.resultdef).rangedef)
                else
                  {Convert array indexes to low_bound..high_bound.}
                  inserttypeconv(right,Torddef.create(Torddef(sinttype).ordtype,

+ 16 - 0
tests/webtbs/tw15364.pp

@@ -0,0 +1,16 @@
+program test;
+
+uses sysutils;
+
+ var
+   a : array [Boolean,Boolean] of string;
+   b : wordbool;
+begin
+  a[False,True] := 'True';
+  a[False,False] := 'False';
+  a[True,True] := 'True';
+  a[True,False] := 'False';
+  b := True;
+  if a[false,b]<>'True' then
+    halt(1);
+end.