Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 6 of 6 total
Thread Problem with array constants
Fri, May 25 2018 3:02 AMPermanent Link

Michael Dreher

var          
 // This compiles...
 array1 : array of string = ['11', '22'];
 array2 : array of string = ['11', '2'];
 array3 : array of string = ['1', '22'];

 // ...but on this I get a compiler error:
 array4 : array of string = ['1', '2'];
   // [Error] Main.wbs (11,30): Expected array of String but instead found
             
Using 2.06B14.

Michael Dreher
Fri, May 25 2018 4:04 AMPermanent Link

Matthew Jones

Michael Dreher wrote:

> ['1', '2'];

Just a ponder - is it thinking those are both chars? The other examples have more than one character each.

--

Matthew Jones
Fri, May 25 2018 5:08 AMPermanent Link

Michael Dreher

"Matthew Jones" wrote:
   // Just a ponder - is it thinking those are both chars? The other
   // examples have more than one character each.

That also came to my mind. But chars are assignable to strings.
I just did another test, int vs. float:

 arr1 : array of double = [1.1, 2.2];
   // compiles

 arr2 : array of double = [1, 2];
   // [Error] Unit1.wbs (32,28): Expected array of Double but instead found

  arr3: array of double = [1, 2.2];
  // [Error] Unit1.wbs (34,31): Expected integer, variant, or enumeration but instead found 2.2

  arr4: array of double = [2.2, 1];
   // compiles

Seems the order of elements also has an effect.

Michael Dreher
Fri, May 25 2018 10:48 AMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 5/25/2018 3:02 AM, Michael Dreher wrote:
> array4 : array of string = ['1', '2'];

Casting issue. Try

  array4 : array of string = [String('1'),String('2')];

Raul
Mon, May 28 2018 2:10 AMPermanent Link

Michael Dreher

Raul wrote:

 // Casting issue. Try...

Thanks for the hint. It seems sufficient to just cast the first array element.

M. Dreher
Tue, May 29 2018 1:53 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com

Michael,

<<  // [Error] Main.wbs (11,30): Expected array of String but instead found >>

I think that Matthew is correct and the compiler thinks that the array elements are characters, not strings.  As far assignability is concerned, yes, characters are normally assignable to strings.  However, EWB expects arrays to be consistently characters or strings because it reserves the right to optimize these in its runtime so that they are not just big arrays of "variants".

I'll have a fix for this in the next build 15.

Tim Young
Elevate Software
www.elevatesoft.com
Image