KScript 文档
ZH

错误代码

KS5019

脚本会调用它自己的 main 函数。main 会在脚本的顶层代码运行后自动运行(参见 main 函数),因此在顶层代码中调用它会使其再运行一次。请删除该调用;快速修复会完成此操作。

<fn name="main">
  <echo>Hello</echo>
</fn>

<do>@main()</do> <!-- warning: main runs by itself after this, so Hello is printed twice -->
fn main() {
  echo 'Hello'
}

@main()    // warning: main runs by itself after this, so Hello is printed twice

在另一个函数内调用,或在留待以后使用的 fn() => @main() 中调用,不会被报告:它只有在有人调用时才会运行。