[FIR] Fix non-fake sources for constructor delegates
This commit is contained in:
+8
-3
@@ -5,6 +5,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -48,8 +49,12 @@ object FirCommonConstructorDelegationIssuesChecker : FirMemberDeclarationChecker
|
||||
|
||||
if (hasPrimaryConstructor) {
|
||||
for (it in otherConstructors) {
|
||||
if (it.delegatedConstructor?.isThis == false) {
|
||||
reporter.reportPrimaryConstructorDelegationCallExpected(it.delegatedConstructor?.source)
|
||||
if (it.delegatedConstructor?.isThis != true) {
|
||||
if (it.delegatedConstructor?.source != null) {
|
||||
reporter.reportPrimaryConstructorDelegationCallExpected(it.delegatedConstructor?.source)
|
||||
} else {
|
||||
reporter.reportPrimaryConstructorDelegationCallExpected(it.source)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -59,7 +64,7 @@ object FirCommonConstructorDelegationIssuesChecker : FirMemberDeclarationChecker
|
||||
// couldn't find proper super() constructor implicitly
|
||||
if (
|
||||
callee is FirErrorNamedReference && callee.diagnostic is ConeAmbiguityError &&
|
||||
it.delegatedConstructor?.source?.startOffset == it.delegatedConstructor?.source?.endOffset
|
||||
it.delegatedConstructor?.source?.kind is FirFakeSourceElementKind
|
||||
) {
|
||||
reporter.reportExplicitDelegationCallRequired(it.source)
|
||||
}
|
||||
|
||||
+2
-4
@@ -6,6 +6,7 @@
|
||||
package org.jetbrains.kotlin.fir.analysis.checkers.declaration
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.FirFakeSourceElementKind
|
||||
import org.jetbrains.kotlin.fir.FirSourceElement
|
||||
import org.jetbrains.kotlin.fir.analysis.checkers.context.CheckerContext
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
@@ -21,13 +22,10 @@ object FirDelegationSuperCallInEnumConstructorChecker : FirMemberDeclarationChec
|
||||
}
|
||||
|
||||
for (it in declaration.declarations) {
|
||||
// checking offsets is needed because we
|
||||
// still have a real source element ("") here,
|
||||
// even if the user hasn't written anything
|
||||
if (
|
||||
it is FirConstructor && !it.isPrimary &&
|
||||
it.delegatedConstructor?.isThis == false &&
|
||||
it.delegatedConstructor?.source?.startOffset != it.delegatedConstructor?.source?.endOffset
|
||||
it.delegatedConstructor?.source?.kind !is FirFakeSourceElementKind
|
||||
) {
|
||||
reporter.report(it.delegatedConstructor?.source)
|
||||
}
|
||||
|
||||
+5
-1
@@ -842,7 +842,11 @@ class DeclarationsConverter(
|
||||
}
|
||||
|
||||
return buildDelegatedConstructorCall {
|
||||
source = constructorDelegationCall.toFirSourceElement()
|
||||
source = if (isImplicit) {
|
||||
constructorDelegationCall.toFirSourceElement().fakeElement(FirFakeSourceElementKind.ImplicitConstructor)
|
||||
} else {
|
||||
constructorDelegationCall.toFirSourceElement()
|
||||
}
|
||||
constructedTypeRef = delegatedType
|
||||
this.isThis = isThis
|
||||
extractArgumentsFrom(firValueArguments, stubMode)
|
||||
|
||||
@@ -1096,7 +1096,11 @@ class RawFirBuilder(
|
||||
hasPrimaryConstructor: Boolean,
|
||||
): FirDelegatedConstructorCall {
|
||||
val isThis = isCallToThis //|| (isImplicit && hasPrimaryConstructor)
|
||||
val source = this.toFirSourceElement()
|
||||
val source = if (isImplicit) {
|
||||
this.toFirSourceElement(FirFakeSourceElementKind.ImplicitConstructor)
|
||||
} else {
|
||||
this.toFirSourceElement()
|
||||
}
|
||||
val delegatedType = when {
|
||||
isThis -> delegatedSelfTypeRef
|
||||
else -> delegatedSuperTypeRef
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ FILE: constructorInObject.kt
|
||||
}
|
||||
|
||||
public? constructor(): R|<anonymous>| {
|
||||
this<R|<anonymous>|>()
|
||||
super<R|B|>()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user