{"record":{"id":"293fad19afe61c21","repo":"OpenRA/OpenRA","slug":"attempted-to-call-wdist-lessthanorequalto-wdist-w","errorCode":null,"errorMessage":"Attempted to call WDist.LessThanOrEqualTo(WDist, WDist) with invalid arguments.","messagePattern":"Attempted to call WDist\\.LessThanOrEqualTo\\(WDist, WDist\\) with invalid arguments\\.","errorType":"exception","errorClass":"LuaException","httpStatus":null,"severity":"error","filePath":"OpenRA.Game/WDist.cs","lineNumber":171,"sourceCode":"\t\t{\n\t\t\tif (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out int b))\n\t\t\t\tthrow new LuaException(\"Attempted to call WDist.Divide(WDist, integer) with invalid arguments.\");\n\n\t\t\treturn new LuaCustomClrObject(a / b);\n\t\t}\n\n\t\tpublic LuaValue LessThan(LuaRuntime runtime, LuaValue left, LuaValue right)\n\t\t{\n\t\t\tif (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))\n\t\t\t\tthrow new LuaException(\"Attempted to call WDist.LessThan(WDist, WDist) with invalid arguments.\");\n\n\t\t\treturn a < b;\n\t\t}\n\n\t\tpublic LuaValue LessThanOrEqualTo(LuaRuntime runtime, LuaValue left, LuaValue right)\n\t\t{\n\t\t\tif (!left.TryGetClrValue(out WDist a) || !right.TryGetClrValue(out WDist b))\n\t\t\t\tthrow new LuaException(\"Attempted to call WDist.LessThanOrEqualTo(WDist, WDist) with invalid arguments.\");\n\n\t\t\treturn a <= b;\n\t\t}\n\n\t\tpublic LuaValue this[LuaRuntime runtime, LuaValue key]\n\t\t{\n\t\t\tget\n\t\t\t{\n\t\t\t\tswitch (key.ToString())\n\t\t\t\t{\n\t\t\t\t\tcase \"Length\": return Length;\n\t\t\t\t\tdefault: throw new LuaException($\"WDist does not define a member '{key}'\");\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tset => throw new LuaException(\"WDist is read-only. Use WDist.New to create a new value\");\n\t\t}\n","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/OpenRA/OpenRA/blob/a520984d91eda9de48a62b1d15c1e3bad0d4fb1a/OpenRA.Game/WDist.cs#L153-L189","documentation":"Lua scripting error from the WDist binding's LessThanOrEqualTo operator (`<=`). Requires both operands to be WDist; throws if either fails conversion.","triggerScenarios":"A Lua comparison like `wdist <= 1024`, `5 <= wdist`, or `wdist <= otherType` — comparison where left or right is not a WDist.","commonSituations":"Scripts using `<=` against a raw integer range/ceiling instead of a constructed WDist.","solutions":["Compare WDist to WDist: `wdist <= WDist.New(ceiling)`.","Or compare raw lengths: `wdist.Length <= 1024`.","Confirm both operands are WDist."],"exampleFix":"-- before\nif wdist <= 2048 then end\n-- after\nif wdist <= WDist.New(2048) then end","handlingStrategy":"type-guard","validationCode":"if a.Length <= b.Length then end","typeGuard":"local function IsWDist(v)\n    local ok, clr = pcall(function() return v.Length end)\n    return ok and clr ~= nil\nend","tryCatchPattern":"if IsWDist(left) and IsWDist(right) then\n    le = left <= right\nelse\n    le = left.Length <= right.Length\nend","preventionTips":["Use `<=` only between two WDist values, or compare .Length ints.","Construct the threshold as a WDist before comparing.","Guard dynamic operands with IsWDist."],"tags":["openra","lua","scripting","wdist","type-mismatch","comparison"],"backgroundTag":null,"analyzedSha":"a520984d91eda9de48a62b1d15c1e3bad0d4fb1a","analyzedAt":"2026-08-13T15:30:14.787Z","schemaVersion":2},"datasetVersion":"2026-08-13T19:17:28.613Z"}