local Queue = {}
-- Create a new queue instance
function New(data : {}?, max_capacity : number?)
return {
_DATA = data or {},
_MAX_CAPACITY = max_capacity or nil,
Pop = Pop,
Push = Push,
Peek = Peek,
Size = Size,
IsEmpty = IsEmpty,
IsFull = IsFull,
Clear = Clear,
GetIterator = GetIterator,
}
end
-- Helper function to access data
local function data(Q)
return Q._DATA
end
-- Helper function to access max capacity
local function max_capacity(Q)
return Q._MAX_CAPACITY
end
-- Get the current size of the queue
function Size(Q) : number
return #data(Q)
end
-- Remove and return the element at the front of the queue
function Pop(Q) : any?
return table.remove(data(Q), 1) -- FIFO behavior
end
-- Add an element to the back of the queue
function Push(Q, v) : boolean
if max_capacity(Q) and Size(Q) >= max_capacity(Q) then
return false -- Queue is full
end
table.insert(data(Q), v)
return true
end
-- View the element at the front without removing it
function Peek(Q) : any?
return data(Q)[1] -- FIFO behavior
end
-- Check if the queue is empty
function IsEmpty(Q) : boolean
return Size(Q) == 0
end
-- Check if the queue is full
function IsFull(Q) : boolean
return max_capacity(Q) and Size(Q) >= max_capacity(Q)
end
-- Clear the queue
function Clear(Q)
Q._DATA = {}
end
-- Get an iterator for the queue
function GetIterator(Q)
local index = 0
local size = Size(Q)
return function()
index = index + 1
if index <= size then
return Q._DATA[index]
end
end
end
return New
Removing certain elements from the code fixes it. For example, removing : boolean from IsFull. Also, moving IsFull to a different position in the script also fixes it, without needing to remove : boolean
I have all beta-features enabled besides the following:
This seems similar to the mostly red line you sometimes get when there is a typechecking error.
I’ve run into issues with the new type-solver having issues with and / or operators used on comparison statements, so it is possible that it is related to this issue.
Also, in this code sample, max_capacity could be nil, which could be leading to the typechecking issue.
Thank you, let’s keep an eye on this and if it doesn’t repro any more we can close it: I suspect that the new solver was updated and it fixed this problem.
Thanks for getting back to me on this.
Can you please look at the Script Analysis widget and let us know what the error is? Then, can you please disable the solver beta to see if it causes this issue?