Skip to content

Conversation

@TheAwiteb
Copy link
Contributor

Check if the token is a keyword or reserved in the function parameters, if it's returns a Reserved error.

Ref: #1045

@schungx
Copy link
Collaborator

schungx commented Oct 26, 2025

If it is a standard keyword then I think we need a more meaningful error message:

fn foo(abc, def, if x { c } else { d })  {}

We may want to say parameter expected on if?

For reserved keywords that should be fine...

Also check it after LexError might be better as the calls might be expensive...

@TheAwiteb
Copy link
Contributor Author

Now this errors are returned

1: fn foo(default, def, if x { c } else { d })  {}
          ^ Syntax error: 'default' is a reserved keyword

and

1: fn foo(abc, def, if x { c } else { d })  {}
                    ^ Syntax error: Expecting name of a parameter but found 'if'

@TheAwiteb TheAwiteb force-pushed the fix-fn-params-reserved-keyword branch from cff268e to f722131 Compare October 26, 2025 13:11
@schungx
Copy link
Collaborator

schungx commented Oct 26, 2025

Only one thing... may not be a good idea to introduce a new error variant just for this case... as existing code do not know how to deal with this.

Can we shoehorn it into an existing error? Do you think?

How about VariableExpected?

@TheAwiteb
Copy link
Contributor Author

How about VariableExpected?

I can do this, but I don't actually except a variable

@schungx
Copy link
Collaborator

schungx commented Oct 26, 2025

A parameter is itself a variable... So technically speaking it is still kosher

@TheAwiteb TheAwiteb force-pushed the fix-fn-params-reserved-keyword branch from f722131 to e44834e Compare October 26, 2025 15:12
@TheAwiteb
Copy link
Contributor Author

Now, instead of

1: fn foo(abc, def, if x { c } else { d })  {}
                    ^ Syntax error: Expecting name of a parameter but found 'if'

it show

1: fn foo(abc, def, if x { c } else { d })  {}
                    ^ Syntax error: Expecting name of a variable

@schungx schungx merged commit 82e7131 into rhaiscript:main Oct 26, 2025
41 of 42 checks passed
@TheAwiteb TheAwiteb deleted the fix-fn-params-reserved-keyword branch October 27, 2025 12:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants