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

[Bug]: Function exists() does not work correctly with array elements. #958

Closed
2 of 3 tasks
benagricola opened this issue Feb 15, 2024 · 1 comment
Closed
2 of 3 tasks
Assignees
Labels
bug Bug that has been reproduced
Milestone

Comments

@benagricola
Copy link

benagricola commented Feb 15, 2024

Duet Forum Discussion Thread

https://forum.duet3d.com/topic/34967/function-exists-does-not-work-correctly-with-array-elements/2?_=1707983978816

Which Duet products are you using?

  • Other

Firmware Version

3.5.0-rc.3+101 (STM32)

Duet Web Control Version

3.5.0-rc.3

Are you using a Single Board Computer (RaspberryPi) with your Duet?

  • Yes I use a SBC.
  • No I do not use a SBC.

Please upload the results of sending M122 in the gcode console.

No response

Please upload the content of your config.g file.

No response

Please upload the content of any other releveant macro files.

; Example on a standard vector
var testVector = { "A","B","C","D" }

; Expected: true, Actual: "C"
echo { exists(var.testVector[2]) }

Details specific to your printer.

N/A

Links to additional info.

No response

What happened?

Expected result
Meta gcode function exists() could be called on an array index and identify whether the index exists in the array.

Observed result
Meta gcode function exists() simply returns the value of the item at the array index, if valid, or throws an index out of bounds error if not.

Steps to reproduce

; Example on a standard vector
var testVector = { "A","B","C","D" }

; Expected: true, Actual: "C"
echo { exists(var.testVector[2]) }

; On blank tool table, which is only extended up to the highest tool defined
M563 P5 S"Test" R0
echo { exists(tools[5]) } ; Returns tool 5 object
echo { exists(tools[49]) } ; Throws array index out of bounds error if tool 49 is not defined
@benagricola benagricola added the bug Bug that has been reproduced label Feb 15, 2024
@benagricola benagricola changed the title [Bug]: F [Bug]: Function exists() does not work correctly with array elements. Feb 15, 2024
@dc42
Copy link
Collaborator

dc42 commented Feb 15, 2024

I confirmed and fixed in the 3.5-dev source code the bug with exists and indexing into testVector. Thanks for reporting this. I was unable to reproduce the bug with exists and indexing into the tools array. Log of test (read in reverse order):

15/02/2024, 09:57:08 	echo {exists(tools[5])}
true
15/02/2024, 09:57:03 	echo {exists(tools[4])}
false
15/02/2024, 09:55:45 	echo exists(tools[4])
false
15/02/2024, 09:55:41 	echo exists(tools[5])
true
15/02/2024, 09:55:33 	m563 p5 s"test"
15/02/2024, 09:55:26 	m563 p5 s"test" r0
Error: M563: unconfigured spindle
15/02/2024, 09:54:26 	echo exists(tools[0])
true
15/02/2024, 09:54:00 	echo exists(tools[49])
false
15/02/2024, 09:53:44 	echo tools[49]
Error:  line 10 column 6: meta command: array index out of bounds
15/02/2024, 09:53:37 	echo tools[0]
{object}

@dc42 dc42 closed this as completed Feb 15, 2024
@dc42 dc42 added this to the 3.5.0 milestone Feb 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that has been reproduced
Projects
None yet
Development

No branches or pull requests

3 participants