From f70e21d9b34bde516e6dda992d5b12b245863d3e Mon Sep 17 00:00:00 2001 From: Allan Jeremy Date: Thu, 2 Jun 2022 17:11:17 +0300 Subject: [PATCH] [Tests] Added LuauPolyfillMap coerceToTable related tests --- bench/static_analysis/LuauPolyfillMap.lua | 29 ----------------------- 1 file changed, 29 deletions(-) diff --git a/bench/static_analysis/LuauPolyfillMap.lua b/bench/static_analysis/LuauPolyfillMap.lua index fc6b20e8..744e32e5 100644 --- a/bench/static_analysis/LuauPolyfillMap.lua +++ b/bench/static_analysis/LuauPolyfillMap.lua @@ -4,35 +4,6 @@ local Array = {} local Object = {} local Map = {} -local None = newproxy(true) - -type Comparable = (any, any) -> number -local defaultSort = function(a: any, b: any): boolean - return type(a) .. tostring(a) < type(b) .. tostring(b) -end - -function Array.sort(array: Array, compare: Comparable?) - -- wrapperCompare interprets compare return value to be compatible with Lua's table.sort - local wrappedCompare = defaultSort - if compare ~= nil and compare ~= None then - if typeof(compare :: any) ~= "function" then - error("invalid argument to Array.sort: compareFunction must be a function") - end - wrappedCompare = function(a, b) - local result = compare(a, b) - if typeof(result) ~= "number" then - -- deviation: throw an error because - -- it's not clearly defined what is - -- the behavior when the compare function - -- does not return a number - error(("invalid result from compare function, expected number but got %s"):format(typeof(result))) - end - return result < 0 - end - end - table.sort(array, wrappedCompare) - return array -end type Array = { [number]: T } type callbackFn = (element: V, key: K, map: Map) -> ()