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