close Warning: Can't synchronize with repository "(default)" (/var/svn/tolp does not appear to be a Subversion repository.). Look in the Trac log for more information.

Opened 21 years ago

Closed 18 years ago

#96 closed defect (fixed)

Variables out of scope

Reported by: jlaybar Owned by: danirus
Priority: normal Milestone:
Component: Kernel Version: head
Severity: normal Keywords:
Cc: Alfredo Torre

Description

This code should return global x and y instead of a and b

Matrix a = Row(0,0);
Matrix b = Row(1,1);

Matrix x = Row(2,2,2);
Matrix y = Row(3,3,3);

Matrix fun1( Matrix q, Matrix p)
{
WriteLn( " q:<<q+?"+NL+"p:<<p+?");
WriteLn( "-------------------------------------------------------------");
WriteLn( " TOL SE VUELVE MAJARA Y ASIGNA MAL LAS VARIABLES
GLOBALES"+NL);
WriteLn( "Asignacion Incorrecta: "+NL+"x:<<x+?"+NL+"y:<<y+?");
WriteLn( "-------------------------------------------------------------");

p+q+x+y

};

Set fun2( Matrix p, Matrix q)
{

Matrix fun3( Matrix x, Matrix y)

{

fun1(x,y)

};

Matrix out = fun3(p,q);

WriteLn( "q:<<q+?"+NL+"p:<<p+?");
WriteLn( "Asignacion Correcta:"+NL+"x:<<x+?"+NL+"y:<<y+?");

p,q,x,y, out?

};

Set salida = fun2(a,b);

Change History (10)

comment:1 Changed 21 years ago by danirus

Status: newassigned

comment:2 Changed 21 years ago by danirus

We can follow the same problem with this short code:

Real fun1(Real p1) { x };

Real fun2(Real p2)
{

Real fun3(Real x) { fun1(x) };
fun3(p2)

};

Real a = 1;
Real x = 2;
Real salida = fun2(a);

Variable salida must be "2" the value of global variable "x", but actually
returns "1" the value of "p2" (assigned to "x" parameter of fun3 in its stack).

comment:3 Changed 21 years ago by danirus

Resolution: fixed
Status: assignedclosed

I have just committed some changes in the core of Tol to give a solution for
this bug.

If you are trying to resolve the value of variable "salida", executing while
reading the code above this messages, practically is ovious that the value
returned must be "2" but not "1".

Implementation Info:

BUserFunction has a new attribute called fInsideLevel_ that stores the level_
used inside a BUsedFunction. When Tol evaluates function's code, all variables
needed are searched into the stack_, but only those with a level_ <= to
fInsideLevel_ are accesible to the function.

comment:4 Changed 21 years ago by danirus

Resolution: fixed
Status: closedreopened

Now appears another problem related with the Scope of variables with the same
fInsideLevel_. A better solution needs a reimplementation of the common stack_
that implements local scopes.

Code has been returned back to previous state in CVS, until we have a definitive
solution. The intermediate solution is also there, not erased.

Daniel

comment:5 Changed 21 years ago by danirus

Resolution: fixed
Status: reopenedclosed

This bug should be already clossed.
The solution was implemented, but someone of us forgot to close it.

comment:6 Changed 21 years ago by danirus

Cc: Alfredo Torre added

comment:7 Changed 21 years ago by danirus

* Bug 181 has been marked as a duplicate of this bug. *

comment:8 Changed 18 years ago by Víctor de Buen Remiro

bug_file_loc: http://cvs.tol-project.org/viewcvs.cgi/tol_tests/tol/Bugzilla/bug_000096

comment:9 Changed 18 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: closedreopened

Problem happens again almost a year ago
I cannot find any version of TOL where this problem is fixed.

comment:10 Changed 18 years ago by Víctor de Buen Remiro

Resolution: fixed
Status: reopenedclosed

It has been a confussion because now scope is DYNAMIC and this is not an error

Note: See TracTickets for help on using tickets.