First line of code colored orange, removing specific elements undoes it


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

image

I have all beta-features enabled besides the following:

  • Next Gen Explorer
  • Next Gen Studio Preview
  • Avatar Auto-Setup Beta

Expected behavior

It shouldn’t be orange; there’s no issue.

1 Like

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.

Not the issue. Setting it to 0 still errors it. In fact, getting rid of the whole New function, doesn’t change anything.