diff --git a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableType.kt b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableType.kt index 2e9c3231441..76f77fb282f 100644 --- a/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableType.kt +++ b/detekt-rules-errorprone/src/main/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableType.kt @@ -47,6 +47,6 @@ class CastToNullableType(config: Config = Config.empty) : Rule(config) { val message = "Use the safe cast ('as? ${nullableTypeElement.innerType?.text}')" + " instead of 'as ${nullableTypeElement.text}'." - report(CodeSmell(issue, Entity.from(expression), message)) + report(CodeSmell(issue, Entity.from(operationReference), message)) } } diff --git a/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableTypeSpec.kt b/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableTypeSpec.kt index 02e832c6b45..b112884f9e3 100644 --- a/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableTypeSpec.kt +++ b/detekt-rules-errorprone/src/test/kotlin/io/gitlab/arturbosch/detekt/rules/bugs/CastToNullableTypeSpec.kt @@ -16,7 +16,7 @@ class CastToNullableTypeSpec { """.trimIndent() val findings = subject.compileAndLint(code) assertThat(findings).hasSize(1) - assertThat(findings).hasStartSourceLocation(2, 22) + assertThat(findings).hasStartSourceLocation(2, 24) assertThat(findings[0]).hasMessage("Use the safe cast ('as? String') instead of 'as String?'.") }