Make global keyword at top level throw

Propose new features and changes
geek
Posts: 1052
Joined: 02 Oct 2013, 22:13
Location: GeekDude
Contact:

Make global keyword at top level throw

20 Jan 2024, 09:31

Especially with the transition from v1, we have a lot of users come into the Discord to ask why code such as this is not working:

Code: Select all

global counter := 1
x::{
	MsgBox counter++
}
but instead throwing "Error: Expected a Number but got an unset variable."

Instead, I think this code should throw a load-time error of "global cannot be specified as a top-level declaration" and maybe also suggest ", it should be moved to the functions where the global variable is being modified".

I think this would clear up a lot of confusion about misleading exceptions in this situation.
User avatar
V2User
Posts: 195
Joined: 30 Apr 2021, 04:04

Re: Make global keyword at top level throw

20 Jan 2024, 21:53

What it throws, should keep the same with MsgBox counter2++, shouldn't it?
Currently, I guess both of them will also have a warning in load time.
User avatar
boiler
Posts: 16981
Joined: 21 Dec 2014, 02:44

Re: Make global keyword at top level throw

21 Jan 2024, 09:10

Are you suggesting it should throw that error at the presence of a global declaration in the global code? That’s what your subject line suggests. See this post by lexikos outlining the reasons for using it there. Based, on that, I don’t expect a change to have it throw an error to be considered.

Return to “Wish List”

Who is online

Users browsing this forum: No registered users and 64 guests