@@ -7,7 +7,7 @@ local table_concat = table.concat
77local tostring = _G .tostring
88local callstack = require (" nattlua.other.callstack" )
99local error_messages = {}
10- --[[ #local type Reason = string | {[number] = any | string}]]
10+ --[[ #local type Reason = {[number] = any | string}]]
1111
1212function error_messages .ErrorMessageToString (tbl --[[ #: List<|string | Reason|>]] )--[[ #: string]]
1313 local out = {}
@@ -27,37 +27,34 @@ function error_messages.ErrorMessageToString(tbl--[[#: List<|string | Reason|>]]
2727 return table_concat (out , " " )
2828end
2929
30- function error_messages .because (msg --[[ #: Reason]] , reason --[[ #: nil | Reason]] )--[[ #: Reason]]
31- if type (msg ) ~= " table" then msg = {msg } end
32-
33- if reason then
34- if type (reason ) ~= " table" then reason = {reason } end
35-
36- table_insert (msg , " because" )
37- table_insert (msg , reason )
38- end
39-
30+ function error_messages .because (msg --[[ #: Reason]] , reason --[[ #: Reason]] )--[[ #: Reason]]
31+ table_insert (msg , " because" )
32+ table_insert (msg , reason )
4033 return msg
4134end
4235
43- function error_messages .context (context --[[ #: Reason]] , reason --[[ #: Reason]] )--[[ #: Reason]]
44- if type (context ) ~= " table" then context = {context } end
36+ function error_messages .argument (i --[[ #: number]] , reason --[[ #: Reason]] )
37+ return {" argument #" , i , " :" , reason }
38+ end
4539
46- if type (reason ) ~= " table" then
47- reason = {context , reason }
48- else
49- reason = {context , reason [1 ], reason [2 ], reason [3 ], reason [4 ], reason [5 ], reason [6 ]}
50- end
40+ function error_messages .return_ (i --[[ #: number]] , reason --[[ #: Reason]] )
41+ return {" return #" , i , " :" , reason }
42+ end
43+
44+ function error_messages .table_key (reason --[[ #: Reason]] )
45+ return {" the key" , reason }
46+ end
5147
52- return reason
48+ function error_messages .table_value (reason --[[ #: Reason]] )
49+ return {" the value" , reason }
5350end
5451
5552do -- string pattern
5653 function error_messages .string_pattern_invalid_construction (a --[[ #: any]] )--[[ #: Reason]]
57- return error_messages . context (
54+ return {
5855 " string pattern must be a string literal, but" ,
59- error_messages .subset (a , " literal string" )
60- )
56+ error_messages .subset (a , " literal string" ),
57+ }
6158 end
6259
6360 function error_messages .string_pattern_match_fail (a --[[ #: any]] , b --[[ #: any]] )--[[ #: Reason]]
@@ -71,10 +68,12 @@ do -- string pattern
7168 end
7269
7370 function error_messages .string_pattern_type_mismatch (a --[[ #: any]] )--[[ #: Reason]]
74- return error_messages .context (
75- {" to compare against a string pattern," , a , " must be a string literal, but" },
76- error_messages .subset (a , " literal string" )
77- )
71+ return {
72+ " to compare against a string pattern," ,
73+ a ,
74+ " must be a string literal, but" ,
75+ error_messages .subset (a , " literal string" ),
76+ }
7877 end
7978end
8079
@@ -226,24 +225,12 @@ function error_messages.mutating_function_argument(obj--[[#: any]], i--[[#: numb
226225 return {
227226 " mutating function argument " ,
228227 obj ,
229- " #" .. i ,
228+ " #" ,
229+ i ,
230230 " without a contract" ,
231231 }
232232end
233233
234- function error_messages .return_type_mismatch (
235- function_node --[[ #: any]] ,
236- output_signature --[[ #: any]] ,
237- output --[[ #: any]] ,
238- reason --[[ #: Reason]] ,
239- i --[[ #: number]]
240- )
241- return error_messages .context (
242- " expected return type " .. tostring (output_signature ) .. " , but found " .. tostring (output ) .. " at return #" .. i .. " :" ,
243- reason
244- )
245- end
246-
247234function error_messages .global_assignment (key --[[ #: any]] , val --[[ #: any]] )--[[ #: Reason]]
248235 return {" _G[" , key , " ] = " , val }
249236end
@@ -272,7 +259,8 @@ function error_messages.mutating_immutable_function_argument(obj--[[#: any]], i-
272259 return {
273260 " mutating function argument" ,
274261 obj ,
275- " #" .. i ,
262+ " #" ,
263+ i ,
276264 " with an immutable contract" ,
277265 }
278266end
303291
304292function error_messages .argument_mutation (i --[[ #: number]] , arg --[[ #: any]] )--[[ #: Reason]]
305293 return {
306- " argument #" .. i ,
294+ " argument #" ,
295+ i ,
307296 arg ,
308297 " can be mutated by external call" ,
309298 }
@@ -329,7 +318,7 @@ function error_messages.invalid_number(value--[[#: any]])--[[#: Reason]]
329318end
330319
331320function error_messages .typeof_lookup_missing (type_name --[[ #: string]] )--[[ #: Reason]]
332- return {" cannot find '" .. type_name .. " ' in the current typesystem scope" }
321+ return {" cannot find '" , type_name , " ' in the current typesystem scope" }
333322end
334323
335324function error_messages .plain_error (msg --[[ #: any]] )--[[ #: Reason]]
@@ -341,7 +330,7 @@ function error_messages.analyzer_error(msg, trace)--[[#: Reason]]
341330end
342331
343332function error_messages .too_many_combinations (total --[[ #: number]] , max --[[ #: number]] )--[[ #: Reason]]
344- return {" too many argument combinations (" .. total .. " > " .. max .. " )" }
333+ return {" too many argument combinations (" , total , " > " , max , " )" }
345334end
346335
347336do
0 commit comments