Module talk:Template invocation
Appearance
Lua error: attempt to compare string with number.
At Template:Toolbar/testcases and Template:3x/testcases test cases fail with this backtrace:
Backtrace: [C]: in function "sort" Module:Template_invocation:107: ? (tail call): ? Module:Template_test_case:140: in function "getInvocation" Module:Template_test_case:642: in function "?" Module:Template_test_case:663: ? [C]: in function "tostring" Module:Template_test_case:786: ? (tail call): ? mw.lua:518: ? [C]: ?
The issue seems to be caused by template invocation, in which a positional parameter is {{=}}
and at least one named parameter is present. I've added test14_equals_sign_parameter
to Module:Template test case/testcases to demonstrate the issue. —andrybak (talk) 14:25, 19 May 2020 (UTC)
- I haven't looked at what this module does or how it's used but the cause of the error is simple. A loop at line 104 uses pairs(invArgs) to put each key (parameter name) into the invArgs_list array. That will include numbers like 1 if the first unnamed parameter is entered, and strings like the names of any named parameters. Line 107 then fails because it cannot sort a mixture of numbers and strings. Someone would have to work out what the module wants to do at that point (why is it sorting the parameters names?) and decide what should happen to numbered parameters. Perhaps they should be omitted, or converted to strings. Or, add a custom sort routine to put the numbers before the strings. Ping me if help is wanted with implementing any of this after deciding what is wanted. Johnuniq (talk) 23:39, 19 May 2020 (UTC)
- Johnuniq, at line 95, the module tries to guess if something that looks like
1=foo=bar
was passed to the template: :: if type(v) == 'string' and v:find('=', 1, true) then :: -- Likely something like 1=foo=bar, we need to do it as a named arg :: break :: end ::
- My guess is that this logic breaks when characters on the left of equals sign are not a valid parameter name or index. Namely, two opening curly braces, as is the case with transclusion of {{=}} as a template. —andrybak (talk) 00:13, 20 May 2020 (UTC)
- Johnuniq, at line 95, the module tries to guess if something that looks like