KScript 文档
ZH

错误代码

KS5005

值的类型与对它的操作不符。例如对数字使用 ->upper()。请先进行转换:$n->to_string()->upper()。

声明为 action: fn 的回调参数需要一个函数。传入 action: null 会在该参数上产生错误。请传入引用,例如 action: @on_connect,或匿名函数,例如 action: fn(session) => @read_status($session)。在脚本函数中,action: fn? = null 会明确接受缺失或为空的回调。

同样的代码会对只能在脚本运行时才会失败的算术和参数发出警告:

<let name="name" value="'Joan'" />
<let name="total" value="$name - 1" /> <!-- warning: '-' needs a number here, but $name holds the text 'Joan' -->
<set name="total" value="[1, 2] + 3" /> <!-- warning: + joins two lists. Use ->push(3) -->
<echo value="'ab'->repeat('x')" /> <!-- warning: the 'count' argument needs a number -->
$name = 'Joan'
$total = $name - 1            // warning: '-' needs a number here, but $name holds the text 'Joan'
$total = [1, 2] + 3           // warning: + joins two lists. Use ->push(3)
echo 'ab'->repeat('x')       // warning: the 'count' argument needs a number

看起来像数字的文本会被转换('5' - 1 的结果为 4),+ 用于连接文本,'ab' * 3 用于重复文本,因此这些都不会发出警告。只有在值是确定的时候检查才会提示:即代码中直接写入的文本,或者只会保存该文本的变量。

Edit this page on GitHub