private fun getFile(name: String) {
val file = fopen(name, "wt")
if (file == null) throw Error("Cannot write file '$name'")
return file
private fun writeM4() {
val file = getFile("config.m4")
fputs(m4Content, file)
...
}
Compiler is fail with errors
Copy code
dsl.kt:77:30: error: type mismatch: inferred type is Unit but CValuesRef<FILE /* = _IO_FILE */>? was expected
fputs(m4Content, file)
^
dsl.kt:86:16: error: type mismatch: inferred type is CPointer<FILE /* = _IO_FILE */>? but Unit was expected
return file
Why it does not infer automatically?
r
russhwolf
07/04/2018, 1:05 PM
Add the return type to
getFile()
. Return type always needs to be explicit in a function with a block body.
o
olonho
07/04/2018, 1:05 PM
Sure, your getFile signature assumes Unit return type, make it return FILE
r
rjhdby
07/04/2018, 1:10 PM
In JVM Kotlin return type inferred automatically. Nikolay, may be you know, JetBrains have plans to add this behavior?