全部配置 / KN-XXEXPLICIT-RETURN-TYPES

XXexplicit-return-types

XXexplicit-return-types · KN-XXEXPLICIT-RETURN-TYPES · 编译器参数(Native)

重要:低 · 工具/诊断 默认:默认关 场合:排障诊断 来源:上游原样

默认值:默认关。内部调试开关,未传则关。使用场合:排障诊断。编译器内部调试。

它是做什么的

用途。强制the compiler to report errors on all public AP…

影响。内部调试开关;勿用于应用工程常规配置。

适用场景。编译器内部调试;应用工程不要打开。

取值说明

枚举

  • 参数描述:Force the compiler to report errors on all public API declarations without an explicit return type. Use the 'warning' level to issue warnings instead of errors. This flag partially enables functionality of `-Xexplicit-api` flag, so please don't use them altogether
可写取值含义使用场景
strict待补依据(源码无 KDoc,文档库暂无条目)
warning待补依据(源码无 KDoc,文档库暂无条目)
disable待补依据(源码无 KDoc,文档库暂无条目)

「待补依据」表示尚未从源码 KDoc / 上游或 CPF 文档整理到该取值的说明;不会编造行为。

定义依据:description/CommonCompilerArguments.kt 在仓库中打开types/ExplicitApiMode.kt 在仓库中打开

怎么用

  1. 配置入口:build.gradle.kts → ohosArm64.binaries.all { freeCompilerArgs += "-XXexplicit-return-types" }
  2. 示例
// 文件:build.gradle.kts(应用的 Kotlin 模块,例如 composeApp)
kotlin {
  ohosArm64 {  // 按实际 native target 调整
    binaries.all {
      freeCompilerArgs += "-XXexplicit-return-types"
    }
  }
}
  1. 生效:Sync 后执行该目标的 compile/link。
  2. 验证:编译日志出现 `-XXexplicit-return-types`。
  3. 回滚:从 binaries.all 的 freeCompilerArgs 中删除该项后 Clean 并重编。
  4. 注意:内部开关,行为无稳定承诺;勿用于应用发布配置。

默认行为 默认关

不写这个配置时,编译器会怎么处理?

此选项默认关闭,不设置时不生效。需要时显式开启。

内部调试开关,未传则关。

溯源与对照

状态
内部(-XX,更不稳定)
版本基线
2.2.21-1.0.0
定义位置类型
编译器参数定义(arguments DSL)
源码路径
compiler/arguments/src/org/jetbrains/kotlin/arguments/description/CommonCompilerArguments.kt 在仓库中打开