Skip to content

Commit

Permalink
Fix crash for DontDowncastCollectionTypes on Synthetic types (#3776)
Browse files Browse the repository at this point in the history
  • Loading branch information
cortinico committed May 14, 2021
1 parent c2a237d commit 1c1dd07
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class DontDowncastCollectionTypes(config: Config) : Rule(config) {
val lhsType = left
.getType(bindingContext)
?.fqNameOrNull()
?.shortName()
?.shortNameOrSpecial()
?.asString()

val rhsType = right
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.gitlab.arturbosch.detekt.rules.bugs
import io.gitlab.arturbosch.detekt.api.Config
import io.gitlab.arturbosch.detekt.rules.setupKotlinEnvironment
import io.gitlab.arturbosch.detekt.test.compileAndLintWithContext
import io.gitlab.arturbosch.detekt.test.lintWithContext
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.spekframework.spek2.Spek
Expand Down Expand Up @@ -174,7 +175,7 @@ class DontDowncastCollectionTypesSpec : Spek({
assertThat(result).isEmpty()
}

it("detects Map type casts") {
it("ignores Map type casts") {
val code = """
fun main() {
val myMap = mutableMapOf(1 to 2)
Expand All @@ -184,6 +185,17 @@ class DontDowncastCollectionTypesSpec : Spek({
val result = subject.compileAndLintWithContext(env, code)
assertThat(result).isEmpty()
}

it("ignores Synthetic types") {
val code = """
import kotlinx.android.synthetic.main.tooltip_progress_bar.view.*
fun main() {
val params = tooltip_guide.layoutParams as LayoutParams
}
"""
val result = subject.lintWithContext(env, code)
assertThat(result).isEmpty()
}
}

describe("type-aliases") {
Expand Down

0 comments on commit 1c1dd07

Please sign in to comment.