2018/03/28

Kotlin & StringFormatMatches lint

val foo = 1
context.getString(R.string.string_format, foo)

↑こういうコードだと, ↓こんなLintエラーが出る.

Errors found:
/xxx/src/xxx/Hoge.kt:100: Error: Wrong argument type for formatting argument '#1' in string_format: conversion is 'd', received <ErrorType> (argument #2 in method call) [StringFormatMatches]
    setText(context.getString(R.string.string_format, foo))

/xxx/src/main/res/values/strings.xml:100: Conflicting argument declaration here
val foo: Int = 1
context.getString(R.string.string_format, foo)

これだとOK.
静的解析で型推論できずにハマっているのかな?