Repository: pinterest/ktlint
Issue: Unused import issue with 38.1

## Expected Behavior
I expect the following to pass formatting.

```kotlin
package com.zak.test

import com.zak.test.MyClass.Intention.Intention1
import com.zak.test.MyClass.Intention.Intention2
import kotlinx.coroutines.CoroutineScope

class MyClass(
    scope: CoroutineScope
) : CoroutineScope by scope {
    private val lambda = {
        var currentState = State()

        for (intention in listOf(Intention1(), Intention2())) {
            when (intention) {
                is Intention1 -> currentState // import is used here
                is Intention2 -> currentState
            }
        }
    }

    fun someFunction() {
        Intention.Intention1() // notice `Intention.` prefix is used even though it is imported
    }

    class State

    sealed class Intention {
        class Intention1 : Intention()
        class Intention2 : Intention()
    }
}

```

## Observed Behavior
Fails with: `Unused import (no-unused-imports)`

If I remove the `someFunction()`, or define it like so:

```kotlin
fun someFunction() {
    Intention1() // import is used, which ktlint likes
}
```

## Steps to Reproduce
run ktlint over the above file ^^

## Your Environment
* Version of ktlint used: `0.38.1` (command line)
* AS `4.0.1` with AGP `3.6`
* Operating System and version: MacOS `10.15.6`


Changed files:
ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt
ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt

diff --git a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt
index 97be493c..4d3b8be0 100644
--- a/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt
+++ b/ktlint-ruleset-standard/src/main/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRule.kt
@@ -12,9 +12,12 @@ import com.pinterest.ktlint.core.ast.isRoot
 import com.pinterest.ktlint.core.ast.parent
 import com.pinterest.ktlint.core.ast.visit
 import org.jetbrains.kotlin.com.intellij.lang.ASTNode
+import org.jetbrains.kotlin.com.intellij.psi.PsiElement
 import org.jetbrains.kotlin.com.intellij.psi.tree.IElementType
 import org.jetbrains.kotlin.kdoc.lexer.KDocTokens
 import org.jetbrains.kotlin.kdoc.psi.impl.KDocLink
+import org.jetbrains.kotlin.psi.KtCallExpression
+import org.jetbrains.kotlin.psi.KtDotQualifiedExpression
 import org.jetbrains.kotlin.psi.KtImportDirective
 import org.jetbrains.kotlin.psi.KtPackageDirective
 
@@ -95,7 +98,7 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {
                 } else if ((type == REFERENCE_EXPRESSION || type == OPERATION_REFERENCE) &&
                     !vnode.isPartOf(IMPORT_DIRECTIVE)
                 ) {
-                    ref.add(Reference(text.trim('`'), vnode.parent(DOT_QUALIFIED_EXPRESSION, true) != null))
+                    ref.add(Reference(text.trim('`'), psi.parentDotQualifiedExpression() != null))
                 } else if (type == IMPORT_DIRECTIVE) {
                     buildNonRedundantImports(vnode.psi as KtImportDirective)
                 }
@@ -179,4 +182,9 @@ class NoUnusedImportsRule : Rule("no-unused-imports") {
     }
 
     private fun String.isComponentN() = componentNRegex.matches(this)
+
+    private fun PsiElement.parentDotQualifiedExpression(): KtDotQualifiedExpression? {
+        val callOrThis = (parent as? KtCallExpression)?.takeIf { it.calleeExpression == this } ?: this
+        return (callOrThis.parent as? KtDotQualifiedExpression)?.takeIf { it.selectorExpression == callOrThis }
+    }
 }
diff --git a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt
index 265646b6..35c38519 100644
--- a/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt
+++ b/ktlint-ruleset-standard/src/test/kotlin/com/pinterest/ktlint/ruleset/standard/NoUnusedImportsRuleTest.kt
@@ -594,6 +594,28 @@ class NoUnusedImportsRuleTest {
         ).isEmpty()
     }
 
+    @Test
+    fun `only redundant sealed sub class imports should be removed 2`() {
+        assertThat(
+            NoUnusedImportsRule().lint(
+                """
+                import com.zak.result.Result.Expected
+                import com.zak.result.Result.Unexpected
+                import org.assertj.core.api.Assertions.assertThat
+
+                fun test() {
+                    assertThat(Result.just(1)).isEqualTo(Expected(1))
+                    assertThat(Result.just(1)).isEqualTo(Result.Expected(1))
+
+                    val ex = Exception()
+                    assertThat(Result.raise(exception)).isEqualTo(Unexpected(ex))
+                    assertThat(Result.raise(exception)).isEqualTo(Result.Unexpected(exception))
+                }
+                """.trimIndent()
+            )
+        ).isEmpty()
+    }
+
     @Test
     fun `only redundant static java function imports should be removed`() {
         assertThat(