Open adambiser opened 3 years ago
This also happens with "local" and type declarations
#option_explicit
type testtype
x
endtype
This should raise an error, but doesn't.
Both of those count as being defined. Using myvariable = "asdf"
by itself without the global definition would trigger the error. Missing off the type (integer, float, etc) gives it the default type but it is still being defined.
Even with #option_explicit used?
Considering global myvariable
an integer is implicit, not explicit.
The type may be implicit but the definition of the variable is explicit.
Not requiring a type works for languages like VB6 that have a Variant type since myvariable = 1
and myvariable = "hello"
both work for Dim myvariable
. (Admittedly terrible practice, since Variant is slow.)
Was just hoping to avoid hair-pulling errors like this:
#option_explicit
global playerx
inc playerx, 0.25
Then can this request be changed to "please add #option_strict to act like #option_explicit, but also force the explicit declaration of variable types"?
(I realize that "Option Strict" in .NET also prevents passing floats to integer parameters, but whatever.)
It's possible the feature could be expanded
Thanks, Paul.
This compiles without error:
Expected result: a compilation error saying "myvariable has not been defined". Using global inside a function also allows the variable to circumvent #option_explicit.
Calling
myvariable = "asdf"
afterward will cause an error because the variable is actually being typed to an integer.