Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003064opensim[REGION] Scripting Enginepublic2009-01-31 10:072011-07-19 08:17
ReporterFrankNichols 
Assigned To 
PrioritynormalSeverityminorReproducibilityalways
StatusfeedbackResolutionopen 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version 
Summary0003064: Scope of local variables handled differently than in SL
DescriptionThe scope of a local variable is handled differently in scripts than in SL:

In the following example abc is both a parameter to function test, and a local variable define within the if statement. In SL this runs correctly, in OS it generates a compile time error.

test(string abc)
{
    llSay(0,abc);
    if(TRUE)
    {
        string abc = "changed";
        llSay(0,abc);
    }
}

default
{
    state_entry()
    {
       test("hello world");
    }
}
Additional InformationMono 2.2
TagsNo tags attached.
Git Revision or version number
Run Mode Grid (1 Region per Sim)
Physics EngineODE
Script Engine
EnvironmentMono / Linux32
Mono VersionOther
Viewer
Attached Files

- Relationships
duplicate of 0002877closedidb Compiling script - getting error CS0136 

-  Notes
(0018803)
makopoppo (manager)
2011-07-09 09:10

I guess OpenSimulator make compile error since it is bad practice to declare the variable which has the same name to the one declared in larger scope. The desired solution would be to fix your script:
---
test(string abc)
{
    llSay(0,abc);
    if(TRUE)
    {
        string abc_1 = "changed";
        llSay(0,abc_1);
    }
}

default
{
    state_entry()
    {
       test("hello world");
    }
}
---

In general, the behavior against "variable hiding" or "shadowing" varies between each other. Some compiler stop compiling, some logs warning message and continue. I personally prefer the former though...
(0018934)
makopoppo (manager)
2011-07-16 02:54

Reminder sent to: idb, StekSpad

integrating 0002877 into 0003064

---
Description When compiling a script I get the following error

*** ERROR START ***

XXXXXXXX: Error compiling script:
Line (XXX,XXX): Error CS0136: A local variable named 'name' cannot be declared in this scope because it would give a different meaning to 'name', which is already used in a 'parent or current' scope to denote something else

*** ERROR END ***

(0008156)
idb (manager)
2008-12-20 04:26

Changes to allow for LSL variable scoping rules in progress.
---
(0018992)
makopoppo (manager)
2011-07-19 08:17

Reminder sent to: DoranZemlja, idb

Integrating 0003152 into 0003064

----
This works fine in SecondLife but not OpenSim:

list foo() {
    return [];
}

default
{
    state_entry()
    {
        integer foo = 5;
        list bar = foo();
    }
}

0009424)
idb (manager)
2009-02-14 02:36
Not the same but very similar to http://opensimulator.org/mantis/view.php?id=2877 [^] [^] that i am currently working on which involves reuse of variable names
----

- Issue History
Date Modified Username Field Change
2009-01-31 10:07 FrankNichols New Issue
2009-01-31 10:07 FrankNichols SVN Revision => 8191
2009-01-31 10:07 FrankNichols Run Mode => Grid (1 Region per Sim)
2009-01-31 10:07 FrankNichols Physics Engine => ODE
2009-01-31 10:07 FrankNichols Environment => Mono / Linux32
2009-01-31 10:07 FrankNichols Mono Version => Other
2009-01-31 10:13 idb Relationship added duplicate of 0002877
2011-07-09 09:10 makopoppo Note Added: 0018803
2011-07-09 09:10 makopoppo Status new => acknowledged
2011-07-16 02:49 makopoppo Status acknowledged => feedback
2011-07-16 02:54 makopoppo Note Added: 0018934
2011-07-19 08:17 makopoppo Note Added: 0018992


Copyright © 2000 - 2012 MantisBT Group
Powered by Mantis Bugtracker