Cancel
Showing results for 
Search instead for 
Did you mean: 

[Bug][PS 13.2.0.1077] assiging string[] to any[] method parameter

Experimenter
Experimenter

Description

i made a generic method which should be able to contain integers or strings, however i don't no the type until runtime therefore i declared the method param as any[] and now it does not accept my string[]

 

Expected Result

string[]  is assigned to any[]

 

Actual Result

error: incompatible types of argument expected any[], passes string[]

 

Steps to reproduce error

  1. create methods in image below
  2. run exc and see error

ps_error.PNG

 

 

2 REPLIES

Re: [Bug][PS 13.2.0.1077] assiging string[] to any[] method parameter

Valued Contributor
Valued Contributor

Hello Frank,
your method does not work, because when you create an array, you did not say that it must have any-format. For example, with func (makeArray (1)) you get an error: "... pass integer [1]".

If you create an array without declaring the format, Plant Simulation self selects a format that uses the minimum resource. For "A" it is a string []. For 1 it is integer. For 1.1 it is real. and so on ...

For example makeArray(1,"A") create a any-format.

that helps:

var a : any[] := makeArray("A")
print func(a)
a:= makeArray(1)
print func(a)

Picture shows another solution

Any-Format.jpg

 

Regards Nadin

Re: [Bug][PS 13.2.0.1077] assiging string[] to any[] method parameter

Siemens Phenom Siemens Phenom
Siemens Phenom

This behavior is actually not intended. If assigning an array to a local variable works, then passing that array to a parameter should also work.  We will change that in version 14.2.

 

Thank you nadin1223 for providing a workaround.

_________________________________________________________________
Did you like the answer? Then click the Thumbs Up button.
Did the answer solve your problem? Then accept the answer as solution.