Archived OpenModelica forums. Posting is disabled.

Alternative forums include GitHub discussions or StackOverflow (make sure to read the Stack Overflow rules; you need to have well-formed questions)


Forgot password? | Forgot username? | Register

Error: vairable not found in scope ?

Error: vairable not found in scope ?

Hello,

with the following piece of code (see below), OpenModelica throw out an error : «tu.mo:22:3-22:71:writable] Error: Variable i.value not found in scope oo. »

It is not clear to me why such an error for line of definition of variable «bool». Did I miss some rules in the modelica langage that prohibits such declaration ?
I'm using OpenModelica v1.17.0 / OMSimulator v2.0.0.post284-gc8ec782-mingw.
For reference, the piece of code below checks, compiles and runs under Dymola 2021.

Code:

package test

//simple enumeration
type t = enumeration( a,  b, c, d);

//simple record that contain an enumeration
record rec
   parameter t value = t.a;
end rec;


// model
model oo
    // fill 2 records
    rec r1(value=t.a);
    rec r2(value=t.b);
   
    //define vector of records
    parameter rec alpha[2]={r1, r2};
    parameter t check=t.b ;
 
  // define vector «bool» which contains 1 or 0 depending on «check» value and content of vector «alpha»
  Integer[size(alpha,1)] bool={(if i.value == check then 1 else 0) for i in alpha};

  end oo;
end test;

Edited by: AntoineR - Jul-20-21 14:04:47

Re: Error: vairable not found in scope ?

I found a workaround, but still remains the issue.

workaround is:

Code:

 Integer bool[size(alpha,1)] ={(if alpha[i].value ==check then 1 else 0) for i in 1:size(alpha,1)} ; 

Still, anyone has clue on what is wrong in the first piece of code below ?

Code:

 Integer[size(alpha,1)] bool={(if i.value == check then 1 else 0) for i in alpha}; 

Re: Error: vairable not found in scope ?

This seems like a bug in the compiler, the model is valid as far as I can see. I opened a ticket for it, see #7767.

(Sorry for the late reply, I've been on vacation. It might be a while until I have time to look at this issue.)

Re: Error: vairable not found in scope ?

Thanks Perost, well noted.

There are 0 guests and 0 other users also viewing this topic
You are here: