Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AP_Scripting: Examples: message_interval: give checker a hint about types #28821

Merged
merged 1 commit into from
Dec 7, 2024

Conversation

IamPete1
Copy link
Member

@IamPete1 IamPete1 commented Dec 6, 2024

A new release of the lua language server results in this invalid CI failure:

Diagnosis complete, 2 problems found, see /__w/ardupilot/ardupilot/lualogs/check.json
/__w/ardupilot/ardupilot/libraries/AP_Scripting/examples/message_interval.lua:51:30
	Code: param-type-mismatch
	Cannot assign `number|uint32_t_ud` to parameter `integer`.
	- `uint32_t_ud` cannot match `integer`
	- Type `uint32_t_ud` cannot match `integer`
/__w/ardupilot/ardupilot/libraries/AP_Scripting/examples/message_interval.lua:49:32
	Code: param-type-mismatch
	Cannot assign `uint32_t_ud` to parameter `number`.
	- `uint32_t_ud` cannot match `number`
	- Type `uint32_t_ud` cannot match `number`

Previously it would not try and guess the types from a table unpack, so we got the benefit of the doubt. Now it seems to try but gets it a bit wrong in this case. Adding the cast annotation means the variables have the correct type so the rest of the file can be checked as normal.

We maybe able to remove the checks again at some point in the future if the checker is improved so it can extract the correct types.

@rmackay9
Copy link
Contributor

rmackay9 commented Dec 6, 2024

I don't think I've ever seen the "cast" keyword before in Lua

@IamPete1
Copy link
Member Author

IamPete1 commented Dec 6, 2024

I don't think I've ever seen the "cast" keyword before in Lua

Strictly is not lua itself, just the markup that the checker uses. There is no change to how the script works, this just means the checks do the right thing. Were trying to use the checks to add type safety to lua which not a type safe language.

The full documentation for the various annotations is here: https://luals.github.io/wiki/annotations/. I have been tying to annotate any scripts I write with them too. Certainty helps catch silly mistakes.

@Hwurzburg
Copy link
Collaborator

@rmackay9 @peterbarker can we get this merged??

@rmackay9 rmackay9 merged commit e4de4c9 into ArduPilot:master Dec 7, 2024
100 checks passed
@rmackay9
Copy link
Contributor

rmackay9 commented Dec 7, 2024

Merged, thanks!

@rmackay9
Copy link
Contributor

I'm including this to help resolve CI failures for 4.6.0-beta2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: 4.6.0-beta2
Development

Successfully merging this pull request may close these issues.

3 participants