AutoComplete Crashes/Closes Studio without Warning

Version: 0.329.0.188854

When typing into Studio’s script editor with the following source code, Studio either crashes, hangs indefinitely, or closes without warning. This happens every time I open this script in a new place in a Script, ModuleScript or LocalScript with Autocomplete enabled. I just patched Studio this evening and have never had any similar issues in previous patches.

The Big Bad Source Code (TM)
local util = require(game.ReplicatedStorage.Modules:WaitForChild("util"))

local Version = {}
Version.__index = Version
Version.names = {"major"; "minor"; "revision"; "build";}
Version.format = "v%d.%d.%d.%d"

function Version.new(v)
	local self = setmetatable({
		
	}, Version)
	
	if type(v) == "table" then
		if v[1] then
			for i, name in pairs(self.names) do
				self[name] = v[i] or 0
			end
		elseif v[self.names[1]] then
			for i, name in pairs(self.names) do
				self[name] = v[name] or 0
			end
		end
	elseif type(v) == "string" then
		-- Split the "a.b.c.d" format
		local tab = util.split(v, ".")
		for i, name in pairs(self.names) do
			self[name] = tonumber(tab[i])
		end
	else
		error(("Invalid version: %s"):format(v))
	end
	return Version
end

function Version:__tostring()
	local t = {}
	for i, name in pairs(self.names) do
		t[i] = self[name]
	end
	return self.format:format(unpack(t))
end

function Version:__eq(other)
	return self.major == other.major
	   and self.minor == other.minor
	   and self.revision == other.revision
	   and self.build == other.build
end

function Version:__lt(other)
	for i, name in pairs(self.names) do
		if self[name] >= other[name] then return false end 
	end
	return true
end

Version.ZERO = Version.new("v0.0.0.0") 

return Version

Repro steps:

  1. Create a new place with a new Script, ModuleScript or LocalScript anywhere within the place.
  2. Paste the above script source one of the simpler script sources in my replies into the script editor.
  3. Turn on Autocomplete if it isn’t on already.
  4. Attempt to type something into the script. Try typing Version.blah = 123 on the line before return Version.
  5. Studio crashes or closes without warning.

This is a really, really nasty bug…needless to say I’m keeping autocomplete off until this is fixed.
OK, so the bug is in fact Bad™, but it’s subtle and not likely to occur with normal script editing. See details below.

Upon further experimentation I’ve narrowed it down to one small change in the source which prevents the bug from happening. On line 32, in the function Version.new, changing return OH_NOES to return Version will cause the bug. I noticed this was a typo in my original code, but I’ve definitely made a similar typo in past version of studio and not had studio crash.

The Big Bad Source Code (TM) Part 2, Electric Boogaloo
local util = require(game.ReplicatedStorage.Modules:WaitForChild("util"))

local Version = {}
Version.__index = Version
Version.names = {"major"; "minor"; "revision"; "build";}
Version.format = "v%d.%d.%d.%d"

function Version.new(v)
	local self = setmetatable({
		
	}, Version)
	
	if type(v) == "table" then
		if v[1] then
			for i, name in pairs(self.names) do
				self[name] = v[i] or 0
			end
		elseif v[self.names[1]] then
			for i, name in pairs(self.names) do
				self[name] = v[name] or 0
			end
		end
	elseif type(v) == "string" then
		-- Split the "a.b.c.d" format
		local tab = util.split(v, ".")
		for i, name in pairs(self.names) do
			self[name] = tonumber(tab[i])
		end
	else
		error(("Invalid version: %s"):format(v))
	end
	return OH_NOES -- Change OH_NOES to Version
end

function Version:__tostring()
	local t = {}
	for i, name in pairs(self.names) do
		t[i] = self[name]
	end
	return self.format:format(unpack(t))
end

function Version:__eq(other)
	return self.major == other.major
	   and self.minor == other.minor
	   and self.revision == other.revision
	   and self.build == other.build
end

function Version:__lt(other)
	for i, name in pairs(self.names) do
		if self[name] >= other[name] then return false end 
	end
	return true
end

Version.ZERO = Version.new("v0.0.0.0") 

return Version

Okay, I’ve boiled it down even further. Here’s more simple code that manages to cause the bug. Apparently removing the call to abc.new stops it.

Summary
local abc = {}

function abc.new(v)
	return OH_NOES -- Change OH_NOES to abc
end


abc.def = abc.new()

return abc
1 Like

What OS are you on?

Windows 10

Confirmed that this issue is already reported and a fix is in the pipeline

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.