Why does one scipt give an error, when I have a script using #pragma strict?

I had a project that suddenly gave me errors when I started adding #pragma strict to my scripts

I removed the code not giving errors, and ended up with these two scripts:

1) PragmaScript: (yes, this is the entire script)

#pragma scrict

2) ScriptInFolder:

function Start ()
    var names : Array = new Array();
    print(0 + names[0]);

ScriptInFolder must be in a folder and running on a gameobject. PragmaScript can be placed anywhere.

The runtime error is:

InvalidProgramException: Invalid IL code in ScriptInFolder:Start (): IL_001f: add

Why does this happen? Shouldn't javascript "fix" these things on the fly, even though I use #pragma strict in one script?

BCE0051: Operator '+' cannot be used with a left hand side of type 'int' and a right hand side of type 'Object'.

That's the error you'd be getting if you had #pragma strict in your second script

change it to

print("0" + names[0]);

and it should work ok

What's happening is that since you're not using #pragma strict in the second script, it's looking at the two objects and can't work out what it should do until runtime. Unfortunately it guesses wrong, and screws up when it tries to do an integer addition

Making it string + object should call .ToString() implicitly on the second object, fixing it

Yeah, I’ve just had the same error while trying to perform the following:

string + int + int + string

the error dissappeared when I’ve changed it to:

string + int + "" + int + string

try with "function Start ()" instead