From ed78183dbdecef735e3398877377827bf6ae1fef Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Wed, 17 Feb 2021 13:06:31 +0100 Subject: [PATCH] FIR: use more specific cone error for unresolved user type ref replaces diagnostic with with specific qualifier --- .../resolve/diagnostics/upperBoundViolated.fir.txt | 4 ++-- .../testData/resolve/fakeRecursiveTypealias.fir.txt | 2 +- .../testData/resolve/multifile/sealedStarImport.fir.txt | 2 +- .../testData/resolve/visibility/exposedSupertype.fir.txt | 2 +- .../problems/KJKComplexHierarchyNestedLoop.fir.txt | 4 ++-- .../analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt | 2 +- .../kotlin/fir/resolve/diagnostics/FirDiagnostics.kt | 4 ++++ .../fir/resolve/providers/impl/FirTypeResolverImpl.kt | 3 ++- .../kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt | 1 - .../testdata/innerDeclarationsResolve/class.fir.txt | 8 ++++---- 10 files changed, 18 insertions(+), 14 deletions(-) diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.fir.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.fir.txt index 9845330a969..f7943cccf56 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/upperBoundViolated.fir.txt @@ -22,8 +22,8 @@ FILE: upperBoundViolated.kt lval b1: R|B| = R|/B.B|() lval b2: R|B| = R|/B.B|() lval b3: R|B| = R|/B.B|() - lval b4: R|B| = R|/B.B|<>() - lval b5: R|B>| = R|/B.B||>() + lval b4: R|B| = R|/B.B|<>() + lval b5: R|B>| = R|/B.B||>() R|/fest|() R|/fest|() R|/fest|() diff --git a/compiler/fir/analysis-tests/testData/resolve/fakeRecursiveTypealias.fir.txt b/compiler/fir/analysis-tests/testData/resolve/fakeRecursiveTypealias.fir.txt index a6efbf787fa..2bade46d399 100644 --- a/compiler/fir/analysis-tests/testData/resolve/fakeRecursiveTypealias.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/fakeRecursiveTypealias.fir.txt @@ -1,3 +1,3 @@ FILE: fakeRecursiveTypealias.kt - public final typealias My = + public final typealias My = public final typealias Your = /Your> diff --git a/compiler/fir/analysis-tests/testData/resolve/multifile/sealedStarImport.fir.txt b/compiler/fir/analysis-tests/testData/resolve/multifile/sealedStarImport.fir.txt index 3122e0aca97..60523804a15 100644 --- a/compiler/fir/analysis-tests/testData/resolve/multifile/sealedStarImport.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/multifile/sealedStarImport.fir.txt @@ -28,7 +28,7 @@ FILE: main.kt super() } - public abstract fun createTest(): + public abstract fun createTest(): public abstract fun createObj(): R|test/Test.O| diff --git a/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.fir.txt b/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.fir.txt index 6634ed366dc..2728e89207e 100644 --- a/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/visibility/exposedSupertype.fir.txt @@ -92,7 +92,7 @@ FILE: exposedSupertype.kt } } - public final class Test7 : { + public final class Test7 : { public constructor(): R|Test7| { super() } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.fir.txt index bcfee608d9a..f2e43195bb9 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/KJKComplexHierarchyNestedLoop.fir.txt @@ -4,9 +4,9 @@ FILE: K1.kt super() } - public final class Q : { + public final class Q : { public constructor(): R|K2.Q| { - super<>() + super<>() } } diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt index 540918218cd..55e5ed82c60 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/coneDiagnosticToFirDiagnostic.kt @@ -27,6 +27,7 @@ private fun ConeDiagnostic.toFirDiagnostic(source: FirSourceElement): FirDiagnos is ConeUnresolvedReferenceError -> FirErrors.UNRESOLVED_REFERENCE.on(source, this.name?.asString() ?: "") is ConeUnresolvedSymbolError -> FirErrors.UNRESOLVED_REFERENCE.on(source, this.classId.asString()) is ConeUnresolvedNameError -> FirErrors.UNRESOLVED_REFERENCE.on(source, this.name.asString()) + is ConeUnresolvedQualifierError -> FirErrors.UNRESOLVED_REFERENCE.on(source, this.qualifier) is ConeHiddenCandidateError -> FirErrors.HIDDEN.on(source, this.candidateSymbol) is ConeAmbiguityError -> if (!this.applicability.isSuccess) { FirErrors.NONE_APPLICABLE.on(source, this.candidates) @@ -42,7 +43,6 @@ private fun ConeDiagnostic.toFirDiagnostic(source: FirSourceElement): FirDiagnos FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(source, this.desiredCount, this.type) is ConeSimpleDiagnostic -> when { source.kind is FirFakeSourceElementKind -> null - this.kind == DiagnosticKind.SymbolNotFound -> FirErrors.UNRESOLVED_REFERENCE.on(source, "") else -> this.getFactory().on(source) } is ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.on(source, this.target) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt index b6cf27c2414..7f4857c7d5f 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/diagnostics/FirDiagnostics.kt @@ -26,6 +26,10 @@ class ConeUnresolvedSymbolError(val classId: ClassId) : ConeDiagnostic() { override val reason: String get() = "Symbol not found for $classId" } +class ConeUnresolvedQualifierError(val qualifier: String) : ConeDiagnostic() { + override val reason: String get() = "Symbol not found for ${qualifier}" +} + class ConeUnresolvedNameError(val name: Name) : ConeDiagnostic() { override val reason: String get() = "Unresolved name: $name" } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index 29f96da6c84..58fc21583e0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -14,6 +14,7 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.* +import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeUnresolvedQualifierError import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeWrongNumberOfTypeArgumentsError import org.jetbrains.kotlin.fir.resolve.getSymbolByLookupTag import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor @@ -98,7 +99,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { areBareTypesAllowed: Boolean ): ConeKotlinType { if (symbol == null) { - return ConeKotlinErrorType(ConeSimpleDiagnostic("Symbol not found, for `${typeRef.render()}`", DiagnosticKind.SymbolNotFound)) + return ConeKotlinErrorType(ConeUnresolvedQualifierError(typeRef.render())) } if (symbol is FirTypeParameterSymbol) { for (part in typeRef.qualifier) { diff --git a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt index bcd4e548432..ddad83daa68 100644 --- a/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt +++ b/compiler/fir/tree/src/org/jetbrains/kotlin/fir/diagnostics/ConeSimpleDiagnostic.kt @@ -29,7 +29,6 @@ enum class DiagnosticKind { SuperNotAllowed, ValueParameterWithNoTypeAnnotation, UnknownCallableKind, - SymbolNotFound, IllegalProjectionUsage, MissingStdlibClass, Other diff --git a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt index 686411ea28e..9fd96710e0f 100644 --- a/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt +++ b/idea/idea-frontend-fir/idea-fir-low-level-api/testdata/innerDeclarationsResolve/class.fir.txt @@ -4,13 +4,13 @@ FILE: class.kt super() } - public final [BODY_RESOLVE] fun q(): { + public final [BODY_RESOLVE] fun q(): { } - private final [BODY_RESOLVE] val y: R|ERROR CLASS: Symbol not found, for `C`| = this@R|/B|.R|/B.q|() - [BODY_RESOLVE] private get(): R|ERROR CLASS: Symbol not found, for `C`| + private final [BODY_RESOLVE] val y: R|ERROR CLASS: Symbol not found for C| = this@R|/B|.R|/B.q|() + [BODY_RESOLVE] private get(): R|ERROR CLASS: Symbol not found for C| - public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: ): { + public final [BODY_RESOLVE] fun foo([BODY_RESOLVE] a: ): { ^foo #(R|/a|, = [BODY_RESOLVE] with@fun (): R|ERROR CLASS: Unresolved name: bar| { ^ #(String(a), this@R|/B|.R|/B.y|) }