Only allow &optional in records

There was some confusing behavior with &optional and locals, so this
should get rid of that by making it an error. However, there is a case
where function parameters are still allowed to have &optional - this is
because there are checks for &default in parameters as well.
This commit is contained in:
Evan Typanski 2025-08-14 09:29:50 -04:00
parent a2680d5eca
commit 4e5a56c5e0
4 changed files with 19 additions and 4 deletions

View file

@ -297,10 +297,10 @@ bool Attributes::CheckAttr(Attr* a) {
case ATTR_IS_USED: break;
case ATTR_OPTIONAL:
if ( global_var )
return AttrError("&optional is not valid for global variables");
if ( ! in_record )
return AttrError("&optional is only valid for record fields");
if ( in_record && Find(ATTR_DEFAULT) )
if ( Find(ATTR_DEFAULT) )
return AttrError("Using &default and &optional together results in &default behavior");
break;