原语到字符转换的扩展函数缺少参数类型

missing parameter type for expanded function for primitive to char conversion

我知道在 stack-overflow 上有类似的问题。

但是,如果下面的任何简单解释在某些地方可用,那就太好了。

val arr1 = Array.tabulate(5)( (_+65) )

编译正常。

val arr2 = Array.tabulate(5)( (_+65).toChar )

是编译时错误。

此外,我想知道如何使用 -Ytyper-debug,如 @som-snyttScala: missing parameter type

编译器编译时:

Array.tabulate(5)( (_+65) )

它将等于:

Array.tabulate(5)(x => (x + 65 ) )

但对于:

Array.tabulate(5)( (_+65).toChar )

将扩展为匿名函数:

Array.tabulate(5)( (x => x + 65).toChar )

编译器将丢失函数体中 x 的上下文。

可以使用scala -Ytyper-debug查看详情:

类型调试输出:

((x) => x.$plus(65)).toChar