YellowAfterlife / GMEdit

A high-end code editor for GameMaker: Studio, GameMaker Studio 2.x, and more!
https://yellowafterlife.itch.io/gmedit
MIT License
308 stars 45 forks source link

#args not being collapsed in some situations #165

Closed Ced-Sharp closed 2 years ago

Ced-Sharp commented 2 years ago

I'm using GMEdit Beta v11.3.0.0 (version Dec 8, 2021) on Windows 11. I'm using GameMaker Studio 2 with IDE v2.3.7.606 and runtime v2.3.7.476.

I did not extensively test this, but here is a simple reproduction. If a file contains a single function, the #args magic works as expected. But if the file contains multiple function, sometimes the first function's #args is collapsed, sometimes not. All other functions in the file are never collapsed.

Example where #args work as expected:

function test() {
  #args a, b = 2, ?c
}

Example where #args does not get collapsed:

function test() {
  #args a, b = 2, ?c
}

function test2() {
  #args d, e = 2, ?f
}

Re-opening that 2nd example shows this:

function test() {
    var a = argument[0];
var b = argument_count > 1 ? argument[1] : 2;
var c = argument_count > 2 ? argument[2] : undefined;
}

function test2() {
    var d = argument[0];
var e = argument_count > 1 ? argument[1] : 2;
var f = argument_count > 2 ? argument[2] : undefined;
}

It does not break the game from running, but I believe this is not the correct behavior for the #args magic.

YellowAfterlife commented 2 years ago

As per documentation, #args is superseded by 2.3's named arguments,

function test(a, b = 2, c) {

}
function test2(d, e = 2, f) {

}

is there a reason why you are trying to use it over the built-in feature?

Ced-Sharp commented 2 years ago

You are completely right, I missed that part from the doc, guess I went too quickly. The issue is still there for the #args operator, but as I don't need to use it at all, I guess it's not an important matter.

I'll leave it up to you to decide if you want to close this, or keep it open to eventually fix it.