compiler bug found!
|
Christina LaFollette
Junior Member
Join date: 28 Feb 2004
Posts: 16
|
04-03-2004 08:29
after the 1.3.2 patch the compiler would let the following piece of code be compiled. if (msg = "hello"  { llSay(0,"he said hello, but... the test is invalid, look at the if statement"  ; } Now prior to 1.3.2 the if statement would not compile and would give you an error, now it compiles just fine and some serious unpredictable results occur, hehe. tootles.
_____________________
--------------------------------------- build it, and they will come.
|
Adam Zaius
Deus
Join date: 9 Jan 2004
Posts: 1,483
|
04-03-2004 09:05
That patch of code is actually a valid statement.
(X = Y) returns true if Y can be copied into X. False if an error occurs.
-Adam
|
Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
|
04-03-2004 09:50
Yes indeed.
You need to switch to equality operator (==). Like Adam says your code is actually valid as your are assigning a string to a typed string variable.
_____________________
** ...you want to do WHAT with that cube? **
|
Christina LaFollette
Junior Member
Join date: 28 Feb 2004
Posts: 16
|
04-03-2004 13:21
i agree with both of you, but an if statement is not the place for that, maybe a for loop is ok.
also, what i was getting at is prior to 1.3.2 it would have given you an error, so if scripters accidently code that now expecting it to be (==) their script will not do what they expect it too, just a word of caution there.
_____________________
--------------------------------------- build it, and they will come.
|
Moleculor Satyr
Fireflies!
Join date: 5 Jan 2004
Posts: 2,650
|
04-03-2004 13:55
I can remember code like that compiling before 1.3.
I can even remember code like that compiling in compilers in other languages when I was in high school.
_____________________
</sarcasm>
|
AnneDroid Lily
Scary robot girl. Rarr.
Join date: 10 Nov 2003
Posts: 41
|
04-03-2004 14:08
From: someone Originally posted by Adam Zaius That patch of code is actually a valid statement.
(X = Y) returns true if Y can be copied into X. False if an error occurs.
-Adam So, in LSL, when would this return false? When the 2 variables are of different types (such as string = vector); when Y could not be cast as X (such as vector = integer); or only when X is not a variable ("hello" = msg)?
|
Christopher Omega
Oxymoron
Join date: 28 Mar 2003
Posts: 1,828
|
04-03-2004 18:28
From: someone Originally posted by Adam Zaius That patch of code is actually a valid statement.
(X = Y) returns true if Y can be copied into X. False if an error occurs.
-Adam I always thought: if(x = y) meant: 1. Copy y into x. 2. evaluate if (x) {
|
Azelda Garcia
Azelda Garcia
Join date: 3 Nov 2003
Posts: 819
|
04-03-2004 18:51
In C, you can put assignment statements anywhere, including in if statements. It has little practical use and is a major source of logical errors. LSL never used to allow it, which I saw as a good thing. If it starts allowing it, one way to get around the problem of logical errors is to switch the equality comparison around: instead of: if( iStatus == SUCCESS ) you write: if( SUCCESS == iStatus ) and make sure SUCCESS is a const/macro.... oh... this wont work in LSL because consts dont exist (I think?) Anyway, the point is, if you forget to write two equals signs, the latter statement will cause a compile-time error, rather than a logical error: if( SUCCESS = iStatus ) -> invalid assignment error Of course, in LSL, this will compile anyway, since SUCCESS will be a variable like any other  Personally Id prefer to make assignments in if statements illegal in LSL. There's no practical usage for allowing them, and they cause untold headaches. Azelda
|
Tcoz Bach
Tyrell Victim
Join date: 10 Dec 2002
Posts: 973
|
04-04-2004 10:39
Constants do exist (NULL_KEY, ZERO_ROTATION), but we can't create them  .
_____________________
** ...you want to do WHAT with that cube? **
|