[v2-rc.2] Cannot set dynamic property to unset

Report problems with documented functionality
User avatar
thqby
Posts: 398
Joined: 16 Apr 2021, 11:18
Contact:

[v2-rc.2] Cannot set dynamic property to unset

Post by thqby » 08 Dec 2022, 05:49

Code: Select all

class cls {
	static prop {
		set {

		}
	}
}
cls.prop := unset  ; Missing a required parameter

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-rc.2] Cannot set dynamic property to unset

Post by lexikos » 08 Dec 2022, 22:07

This is not a bug.

There is nothing in the documentation to indicate that this is supported, unless you count the assignment as an implicit function call.
Within a function call, array literal or object literal, the keyword unset can be used to explicitly omit the parameter or value. An unset expression has one of the following effects:
•For a user-defined function, the parameter's default value is used.
When you omit a required parameter, you get an error message. The value parameter is required.

If you wish to handle this case, you must define the property setter explicitly with an optional parameter and DefineProp.

My initial intention was for v2.0 to support unset/?/?? only for function parameters and variables, with a later release extending them to other parts of the syntax, after giving more time for testing and thinking through how it should all work. Assigning unset is allowed (but probably not documented) in v2.0-rc.1+ for value properties because I found that the missing value wasn't being caught, and was erroneously being assigned as "".

In future, perhaps a simple solution would be for set? to indicate that the value parameter is optional. It could always be optional, but that might negatively impact error-detection/reporting.

User avatar
thqby
Posts: 398
Joined: 16 Apr 2021, 11:18
Contact:

Re: [v2-rc.2] Cannot set dynamic property to unset

Post by thqby » 09 Dec 2022, 02:57

I got it. I see that the following code is supported by the previous fixes, and I think the above code is also applicable to this.

Code: Select all

class cls {
	static prop := 0
}
cls.prop := unset

lexikos
Posts: 9560
Joined: 30 Sep 2013, 04:07
Contact:

Re: [v2-rc.2] Cannot set dynamic property to unset

Post by lexikos » 09 Dec 2022, 17:30

static prop := 0 creates a value property. As I said, assigning unset is allowed for value properties. There is no setter function, and no function parameters, mandatory or otherwise.

I have no idea what "the above code is also applicable to this" means.

User avatar
thqby
Posts: 398
Joined: 16 Apr 2021, 11:18
Contact:

Re: [v2-rc.2] Cannot set dynamic property to unset

Post by thqby » 10 Dec 2022, 02:14

Before you explain, I thought both codes were available, so I submit this post.

Post Reply

Return to “Bug Reports”