YoYoGames / GameMaker-Bugs

Public tracking for GameMaker bugs
24 stars 8 forks source link

Inconsistencies with array refs in expressions #2039

Closed tinkerer-red closed 1 year ago

tinkerer-red commented 1 year ago

Description

When passing an array into an if expression the game crashes, I am unsure if this is intended given arrays are simply refs, as well as structs, and methods. If structs, functions, and methods all pass the if statement, logically arrays would as well.

test code:

var _test = undefined;
if (_test) {
    log("undefined") //should not log
}
var _test = false;
if (_test) {
    log("false") //should not log
}
var _test = true;
if (_test) {
    log("true") //should log
}
//var _test = [];
//if (_test) {
//  log("array") //should log
//}
var _test = {};
if (_test) {
    log("struct") //should log
}
var _test = log;
if (_test) {
    log("function") //should log
}
var _test = function(){};
if (_test) {
    log("method") //should log
}

I originally thought that this was because internally they had made use of valueOf to return true, although when real() the struct and method returned NaN which fails in if expressions. So there seems to be another approach going on which manually approved these specifically.

EDIT : It is using bool() internally, obviously. I dont know how I forgot about that function. image

Expected Change

if (_arr) expression should pass

Steps To Reproduce

copy paste code

How reliably can you recreate this issue using your steps above?

Always

Which version of GameMaker are you reporting this issue for?

2023.8.2 (Monthly)

Which platform(s) are you seeing the problem on?

Windows

Contact Us Package Attached?

Sample Project Added?

rwkay commented 1 year ago

bool( array_var ) has always been an error... I have no plans on changing that, this is the same code that handles the implicit conversion to boolean so it is an error.

tinkerer-red commented 1 year ago

What's the logic for having the others returning as true then? Like I could understand if a struct if they made use of valueOf, and kind of also could understand functions given they use to be an index reference and it's for legacy support. Are these intentional choices or were grandfathered in from prior code?

rwkay commented 1 year ago

we wanted to leave the valueOf route open, functions used to be integers, methods are structs... they were all intentional choices - we made an array an error as it used to valid code to see an array variable being used without the deference and GM7 and GM8 actually did the dereference for you automatically i.e. a and a[0] were the same thing. We want to discourage that (we still see users migrating old code and we want them to fix it)