From c8f8908a013bf19f402ffd5fc7c1651c9ec7f0ac Mon Sep 17 00:00:00 2001 From: Nick Date: Mon, 17 Aug 2020 17:21:46 +0300 Subject: [PATCH] [FIR] Add NO_THIS & INSTANCE_ACCESS_BEFORE_SUPER_CALL --- .../diagnostics/anonymousObjectByDelegate.kt | 2 +- .../instanceAccessBeforeSuperCall.kt | 50 +++++++++ .../instanceAccessBeforeSuperCall.txt | 106 ++++++++++++++++++ .../testData/resolve/expresssions/access.txt | 2 +- .../expresssions/invoke/farInvokeExtension.kt | 2 +- .../callableReferences/implicitTypes.txt | 2 +- .../fir/FirDiagnosticsTestGenerated.java | 5 + ...DiagnosticsWithLightTreeTestGenerated.java | 5 + .../collectors/AbstractDiagnosticCollector.kt | 49 ++------ .../ErrorNodeDiagnosticCollectorComponent.kt | 24 +--- .../diagnostics/FirDefaultErrorMessages.kt | 8 ++ .../fir/analysis/diagnostics/FirErrors.kt | 2 + .../converter/DeclarationsConverter.kt | 4 +- .../fir/lightTree/fir/ValueParameter.kt | 4 +- .../kotlin/fir/builder/RawFirBuilder.kt | 12 +- .../kotlin/fir/resolve/ResolveUtils.kt | 7 +- .../kotlin/fir/resolve/calls/FirReceivers.kt | 15 +++ .../calls/tower/FirTowerResolverSession.kt | 8 +- .../fir/resolve/diagnostics/FirDiagnostics.kt | 4 + ...rCallCompletionResultsWriterTransformer.kt | 7 ++ .../FirSpecificTypeResolverTransformer.kt | 21 +++- .../FirDeclarationsResolveTransformer.kt | 17 ++- .../FirExpressionsResolveTransformer.kt | 72 ++++++++++-- .../fir/diagnostics/ConeSimpleDiagnostic.kt | 1 + .../jvm/instanceAccessBeforeSuperCall.args | 4 + .../cli/jvm/instanceAccessBeforeSuperCall.kt | 21 ++++ .../cli/jvm/instanceAccessBeforeSuperCall.out | 31 +++++ .../diagnostics/tests/EnumEntryAsType.fir.kt | 4 +- .../bound/noThisInSuperCall.fir.kt | 3 - .../bound/noThisInSuperCall.kt | 1 + .../cast/bare/ErrorsInSubstitution.fir.kt | 2 +- .../tests/cast/bare/FromErrorType.fir.kt | 2 +- .../typeParametersInAnnonymousObject.fir.kt | 4 +- ...eParametersInAnnonymousObject_after.fir.kt | 4 +- ...aultValuesWithConstantsInAnnotation.fir.kt | 2 +- .../delegatedProperty/thisInDelegate.fir.kt | 2 +- .../finalUpperBoundWithoutOverride.fir.kt | 2 +- .../controlStructuresErrors.fir.kt | 2 +- ...yFromDeclarationOfAnonymousFunction.fir.kt | 6 +- .../errorUpperBoundConstraint.fir.kt | 2 +- .../inference/extensionLambdasAndArrow.fir.kt | 8 +- .../tests/inner/innerThisSuper.fir.kt | 4 +- .../nestedVsInnerAccessOuterMember.fir.kt | 4 +- .../labels/labeledFunctionLiteral.fir.kt | 6 +- .../UnavaliableQualifiedThis.fir.kt | 4 +- .../tests/regressions/kt30245.fir.kt | 28 ++--- .../tests/regressions/noThis.fir.kt | 10 -- .../diagnostics/tests/regressions/noThis.kt | 1 + ...tyWithTwoCorrespondingFunctionTypes.fir.kt | 2 +- .../scopes/classHeader/constructors.fir.kt | 4 +- ...ctorArgumentsInSecondaryConstructor.fir.kt | 4 +- ...initializerScopeOfExtensionProperty.fir.kt | 2 +- .../tests/scopes/kt250.617.10.fir.kt | 2 +- ...seGenericFromInnerExtendingSameBase.fir.kt | 2 +- ...eGenericFromInnerExtendingSameBase2.fir.kt | 2 +- .../accessBaseWithSameExtension.fir.kt | 2 +- .../accessGenericBaseWithSameExtension.fir.kt | 4 +- .../innerInstanceCreation.fir.kt | 4 +- .../headerCallChecker/lambdaAsArgument.fir.kt | 8 +- .../headerCallChecker/memberFunAccess.fir.kt | 4 +- .../objectLiteralAsArgument.fir.kt | 4 +- ...bjectLiteralAsDefaultValueParameter.fir.kt | 2 +- .../headerCallChecker/operatorCall.fir.kt | 4 +- .../headerCallChecker/passingInstance.fir.kt | 4 +- .../headerCallChecker/propertyAccess.fir.kt | 4 +- .../propertyAccessUnitialized.fir.kt | 4 +- .../headerCallChecker/superFunAccess.fir.kt | 4 +- .../superFunAccessOverriden.fir.kt | 4 +- .../superPropertyAccess.fir.kt | 4 +- .../thisAsExtensionReceiver.fir.kt | 12 +- .../tests/thisAndSuper/QualifiedThis.fir.kt | 2 +- .../thisInFunctionLiterals.fir.kt | 2 +- .../thisInPropertyInitializer.fir.kt | 2 +- .../thisInToplevelFunction.fir.kt | 4 +- ...tedTypeAliasQualifiedByDerivedClass.fir.kt | 4 +- .../typealias/innerTypeAliasAsType.fir.kt | 12 +- .../tests/typealias/localTypeAlias.fir.kt | 4 +- .../localTypeAliasConstructor.fir.kt | 4 +- .../diagnostics/tests/typealias/nested.fir.kt | 4 +- .../nestedCapturingTypeParameters.fir.kt | 8 +- .../dsl/errors/accessToOuterThis.fir.kt | 6 +- .../callableReferenceOnUnresolvedLHS.fir.kt | 2 +- .../testsWithStdLib/regression/kt37727.fir.kt | 4 +- .../contractFunction/neg/2.fir.kt | 6 +- .../diagnostics/notLinked/dfa/neg/1.fir.kt | 4 +- .../kotlin/cli/CliTestGenerated.java | 5 + 86 files changed, 526 insertions(+), 219 deletions(-) create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt create mode 100644 compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.txt create mode 100644 compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.args create mode 100644 compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt create mode 100644 compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out delete mode 100644 compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt delete mode 100644 compiler/testData/diagnostics/tests/regressions/noThis.fir.kt diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt index e86f6686623..f635f85286c 100644 --- a/compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/anonymousObjectByDelegate.kt @@ -14,4 +14,4 @@ fun A.test_2() { object : B by b {} } -class D(val x: String, val y: String = this.x) {} \ No newline at end of file +class D(val x: String, val y: String = this.x) {} \ No newline at end of file diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt new file mode 100644 index 00000000000..31ffed6cc45 --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt @@ -0,0 +1,50 @@ +class A { + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + fun getSomeInt() = 10 + var keker = "test" +} + +class B(other: B = this) + +class C() { + constructor(x: Int) : this({ + val a = 10 + this + }) {} +} + +class D { + var a = 20 + constructor() { + this.a = 10 + } +} + +fun main() { + val x1: String.() -> String = if (true) { + { this } + } else { + { this } + } +} + +fun test(f: F) {} + +val a = this + +class F(var a: Int, b: Int, closure: () -> Unit, instance: F?) { + constructor(x: Int) : this(x, x, { + val a = 10 + this + test(this) + this.a = 20 + }, this) { + this.a = 30 + } +} + +open class Base(val x: Int) + +class Derived : Base(this.y) { // FE 1.0 reports NO_THIS here + val y = 42 +} diff --git a/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.txt b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.txt new file mode 100644 index 00000000000..e6cb08d8e8a --- /dev/null +++ b/compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.txt @@ -0,0 +1,106 @@ +FILE: instanceAccessBeforeSuperCall.kt + public final class A : R|kotlin/Any| { + public constructor(x: R|kotlin/Int| = #(), other: R|A| = this@R|/A|, header: R|kotlin/String| = #): R|A| { + super() + } + + public final fun getSomeInt(): R|kotlin/Int| { + ^getSomeInt Int(10) + } + + public final var keker: R|kotlin/String| = String(test) + public get(): R|kotlin/String| + public set(value: R|kotlin/String|): R|kotlin/Unit| + + } + public final class B : R|kotlin/Any| { + public constructor(other: R|B| = this#): R|B| { + super() + } + + } + public final class C : R|kotlin/Any| { + public constructor(): R|C| { + super() + } + + public constructor(x: R|kotlin/Int|): R|C| { + this(fun (): R|ERROR CLASS: Cannot access '''' before superclass constructor has been called| { + lval a: R|kotlin/Int| = Int(10) + ^ this@R|/C| + } + ) + } + + } + public final class D : R|kotlin/Any| { + public final var a: R|kotlin/Int| = Int(20) + public get(): R|kotlin/Int| + public set(value: R|kotlin/Int|): R|kotlin/Unit| + + public constructor(): R|D| { + super() + this@R|/D|.R|/D.a| = Int(10) + } + + } + public final fun main(): R|kotlin/Unit| { + lval x1: R|kotlin/String.() -> kotlin/String| = when () { + Boolean(true) -> { + fun (it: R|kotlin/String|): R|ERROR CLASS: 'this' is not defined in this context| { + ^ this# + } + + } + else -> { + fun (it: R|kotlin/String|): R|ERROR CLASS: 'this' is not defined in this context| { + ^ this# + } + + } + } + + } + public final fun test(f: R|F|): R|kotlin/Unit| { + } + public final val a: R|ERROR CLASS: 'this' is not defined in this context| = this# + public get(): R|ERROR CLASS: 'this' is not defined in this context| + public final class F : R|kotlin/Any| { + public constructor(a: R|kotlin/Int|, b: R|kotlin/Int|, closure: R|() -> kotlin/Unit|, instance: R|F?|): R|F| { + super() + } + + public final var a: R|kotlin/Int| = R|/a| + public get(): R|kotlin/Int| + public set(value: R|kotlin/Int|): R|kotlin/Unit| + + public constructor(x: R|kotlin/Int|): R|F| { + this(R|/x|, R|/x|, fun (): R|kotlin/Unit| { + lval a: R|kotlin/Int| = Int(10) + this@R|/F| + R|/test|(this@R|/F|) + this@R|/F|.# = Int(20) + } + , this@R|/F|) + this@R|/F|.R|/F.a| = Int(30) + } + + } + public open class Base : R|kotlin/Any| { + public constructor(x: R|kotlin/Int|): R|Base| { + super() + } + + public final val x: R|kotlin/Int| = R|/x| + public get(): R|kotlin/Int| + + } + public final class Derived : R|Base| { + public constructor(): R|Derived| { + super(this#.#) + } + + public final val y: R|kotlin/Int| = Int(42) + public get(): R|kotlin/Int| + + } diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/access.txt b/compiler/fir/analysis-tests/testData/resolve/expresssions/access.txt index 5b203daae18..e29e4aab883 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/access.txt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/access.txt @@ -36,7 +36,7 @@ FILE: access.kt ^plus String() } - public final fun R|Foo|.check(): { + public final fun R|Foo|.check(): R|ERROR CLASS: Ambiguity: plus, [kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus, kotlin/Int.plus]| { ^check this@R|/Bar.check|.R|/Foo.abc|().#(this@R|/Bar|.R|/Bar.bar|()) } diff --git a/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/farInvokeExtension.kt b/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/farInvokeExtension.kt index 3b464150f41..5518db20fad 100644 --- a/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/farInvokeExtension.kt +++ b/compiler/fir/analysis-tests/testData/resolve/expresssions/invoke/farInvokeExtension.kt @@ -2,7 +2,7 @@ fun x() {} -operator fun Int.invoke(): Foo = this@Foo +operator fun Int.invoke(): Foo = this@Foo class Foo { diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.txt index a4aada100e8..8ed1ac98753 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/implicitTypes.txt @@ -11,6 +11,6 @@ FILE: implicitTypes.kt public final fun loop1(): R|(kotlin/Any?) -> kotlin/Nothing| { ^loop1 #(::#) } - public final fun loop2(): { + public final fun loop2(): R|ERROR CLASS: cycle| { ^loop2 R|/loop1|() } diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index ffe1873fd81..89e20d1f7cd 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -976,6 +976,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/infixFunctions.kt"); } + @TestMetadata("instanceAccessBeforeSuperCall.kt") + public void testInstanceAccessBeforeSuperCall() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt"); + } + @TestMetadata("interfaceWithSuperclass.kt") public void testInterfaceWithSuperclass() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt"); diff --git a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index a964f8408a0..694be47c9e0 100644 --- a/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/analysis-tests/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -976,6 +976,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/infixFunctions.kt"); } + @TestMetadata("instanceAccessBeforeSuperCall.kt") + public void testInstanceAccessBeforeSuperCall() throws Exception { + runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/instanceAccessBeforeSuperCall.kt"); + } + @TestMetadata("interfaceWithSuperclass.kt") public void testInterfaceWithSuperclass() throws Exception { runTest("compiler/fir/analysis-tests/testData/resolve/diagnostics/interfaceWithSuperclass.kt"); diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt index b1f68c7f26b..c6f2f50c772 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/AbstractDiagnosticCollector.kt @@ -6,19 +6,24 @@ package org.jetbrains.kotlin.fir.analysis.collectors import org.jetbrains.kotlin.fir.FirElement +import org.jetbrains.kotlin.fir.FirFakeSourceElementKind import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.analysis.checkers.context.PersistentCheckerContext import org.jetbrains.kotlin.fir.analysis.collectors.components.* import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnostic import org.jetbrains.kotlin.fir.declarations.* +import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.resolve.ScopeSession import org.jetbrains.kotlin.fir.resolve.SessionHolder import org.jetbrains.kotlin.fir.resolve.collectImplicitReceivers import org.jetbrains.kotlin.fir.resolve.defaultType -import org.jetbrains.kotlin.fir.types.* +import org.jetbrains.kotlin.fir.types.ConeKotlinType +import org.jetbrains.kotlin.fir.types.FirErrorTypeRef +import org.jetbrains.kotlin.fir.types.FirTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef +import org.jetbrains.kotlin.fir.types.coneTypeSafe import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor import org.jetbrains.kotlin.name.Name @@ -46,8 +51,6 @@ abstract class AbstractDiagnosticCollector( @Suppress("LeakingThis") private var context = PersistentCheckerContext(this) - private var lastExpression: FirExpression? = null - fun initializeComponents(vararg components: AbstractDiagnosticCollectorComponent) { if (componentsInitialized) { throw IllegalStateException() @@ -120,8 +123,10 @@ abstract class AbstractDiagnosticCollector( } override fun visitPropertyAccessor(propertyAccessor: FirPropertyAccessor, data: Nothing?) { - val property = context.containingDeclarations.last() as FirProperty - visitWithDeclarationAndReceiver(propertyAccessor, property.name, property.receiverTypeRef) + if (propertyAccessor !is FirDefaultPropertyAccessor) { + val property = context.containingDeclarations.last() as FirProperty + visitWithDeclarationAndReceiver(propertyAccessor, property.name, property.receiverTypeRef) + } } override fun visitValueParameter(valueParameter: FirValueParameter, data: Nothing?) { @@ -140,33 +145,13 @@ abstract class AbstractDiagnosticCollector( visitWithDeclaration(anonymousInitializer) } - override fun visitExpression(expression: FirExpression, data: Nothing?) { - expression.runComponents() - withExpression(expression) { - expression.acceptChildren(this, null) - } - } - override fun visitBlock(block: FirBlock, data: Nothing?) { visitExpression(block, data) } override fun visitTypeRef(typeRef: FirTypeRef, data: Nothing?) { - if (typeRef === lastExpression?.typeRef) { - return - } - super.visitTypeRef(typeRef, null) - } - - override fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: Nothing?) { - typeOperatorCall.runComponents() - withExpression(typeOperatorCall) { - typeOperatorCall.acceptChildren(this, null) - } - if (typeOperatorCall.operation == FirOperation.AS) { - // NB: in this case conversionTypeRef === typeRef, so we *should* visit it explicitly - typeOperatorCall.conversionTypeRef.runComponents() - typeOperatorCall.conversionTypeRef.acceptChildren(this, null) + if (typeRef.source != null && typeRef.source?.kind !is FirFakeSourceElementKind) { + super.visitTypeRef(typeRef, null) } } @@ -201,16 +186,6 @@ abstract class AbstractDiagnosticCollector( } } - private inline fun withExpression(expression: FirExpression, block: () -> R): R { - val previousExpression = lastExpression - lastExpression = expression - try { - return block() - } finally { - lastExpression = previousExpression - } - } - private inline fun withLabelAndReceiverType( labelName: Name?, owner: FirDeclaration, diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt index f7f5d61e037..52c2a739ad6 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/collectors/components/ErrorNodeDiagnosticCollectorComponent.kt @@ -33,18 +33,6 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect } override fun visitErrorTypeRef(errorTypeRef: FirErrorTypeRef, data: CheckerContext) { - when (val lastContainingDeclaration = data.containingDeclarations.lastOrNull()) { - is FirDefaultPropertyAccessor -> { - // It always uses the same type ref as the corresponding property - return - } - else -> if ( - errorTypeRef.source?.kind is FirFakeSourceElementKind || - lastContainingDeclaration?.source?.kind is FirFakeSourceElementKind - ) { - return - } - } val source = errorTypeRef.source ?: return runCheck { reportFirDiagnostic(errorTypeRef.diagnostic, source, it) } } @@ -90,13 +78,12 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect is ConeIllegalAnnotationError -> FirErrors.NOT_AN_ANNOTATION_CLASS.on(source, diagnostic.name.asString()) is ConeWrongNumberOfTypeArgumentsError -> FirErrors.WRONG_NUMBER_OF_TYPE_ARGUMENTS.on(source, diagnostic.desiredCount, diagnostic.type) - is ConeSimpleDiagnostic -> if (source.kind is FirFakeSourceElementKind) { - null - } else if (diagnostic.kind == SymbolNotFound) { - FirErrors.UNRESOLVED_REFERENCE.on(source, "") - } else { - diagnostic.getFactory().on(source) + is ConeSimpleDiagnostic -> when { + source.kind is FirFakeSourceElementKind -> null + diagnostic.kind == SymbolNotFound -> FirErrors.UNRESOLVED_REFERENCE.on(source, "") + else -> diagnostic.getFactory().on(source) } + is ConeInstanceAccessBeforeSuperCall -> FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL.on(source, diagnostic.target) is ConeStubDiagnostic -> null is ConeIntermediateDiagnostic -> null else -> throw IllegalArgumentException("Unsupported diagnostic type: ${diagnostic.javaClass}") @@ -110,6 +97,7 @@ class ErrorNodeDiagnosticCollectorComponent(collector: AbstractDiagnosticCollect Syntax -> FirErrors.SYNTAX_ERROR ReturnNotAllowed -> FirErrors.RETURN_NOT_ALLOWED UnresolvedLabel -> FirErrors.UNRESOLVED_LABEL + NoThis -> FirErrors.NO_THIS IllegalConstExpression -> FirErrors.ILLEGAL_CONST_EXPRESSION IllegalUnderscore -> FirErrors.ILLEGAL_UNDERSCORE DeserializationError -> FirErrors.DESERIALIZATION_ERROR diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt index cae34159115..250ceab62cb 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirDefaultErrorMessages.kt @@ -53,6 +53,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INAPPLICABLE_INFI import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INAPPLICABLE_LATEINIT_MODIFIER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INCOMPATIBLE_MODIFIERS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INFERENCE_ERROR +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INSTANCE_ACCESS_BEFORE_SUPER_CALL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INTERFACE_WITH_SUPERCLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.INVALID_TYPE_OF_ANNOTATION_MEMBER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.LEAKED_IN_PLACE_LAMBDA @@ -67,6 +68,7 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NON_PRIVATE_CONST import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_AN_ANNOTATION_CLASS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_LOOP_LABEL import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NOT_A_SUPERTYPE +import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NO_THIS import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NO_TYPE_FOR_TYPE_PARAMETER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.NULLABLE_TYPE_OF_ANNOTATION_MEMBER import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors.OTHER_ERROR @@ -145,11 +147,17 @@ class FirDefaultErrorMessages : DefaultErrorMessages.Extension { map.put(ERROR_FROM_JAVA_RESOLUTION, "Java resolution error") // map.put(UNKNOWN_CALLABLE_KIND, ...) // & // map.put(MISSING_STDLIB_CLASS, ...) // & + map.put(NO_THIS, "'this' is not defined in this context") // Super map.put(SUPER_IS_NOT_AN_EXPRESSION, "Super cannot be a callee") map.put(SUPER_NOT_AVAILABLE, "No supertypes are accessible in this context") map.put(ABSTRACT_SUPER_CALL, "Abstract member cannot be accessed directly") + map.put( + INSTANCE_ACCESS_BEFORE_SUPER_CALL, + "Cannot access ''{0}'' before superclass constructor has been called", + TO_STRING + ) // Supertypes map.put(TYPE_PARAMETER_AS_SUPERTYPE, "Type parameter as supertype") diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt index 6889f3e4ecf..0ea58e062b5 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/diagnostics/FirErrors.kt @@ -46,11 +46,13 @@ object FirErrors { val ERROR_FROM_JAVA_RESOLUTION by error0() val UNKNOWN_CALLABLE_KIND by error0() val MISSING_STDLIB_CLASS by error0() + val NO_THIS by error0() // Super val SUPER_IS_NOT_AN_EXPRESSION by error0() val SUPER_NOT_AVAILABLE by error0() val ABSTRACT_SUPER_CALL by error0() + val INSTANCE_ACCESS_BEFORE_SUPER_CALL by error1() // Supertypes val TYPE_PARAMETER_AS_SUPERTYPE by error0() diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt index 6ec67b8886c..061d452eb82 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/converter/DeclarationsConverter.kt @@ -711,7 +711,7 @@ class DeclarationsConverter( val defaultVisibility = classWrapper.defaultConstructorVisibility() val firDelegatedCall = buildDelegatedConstructorCall { source = delegatedConstructorSource ?: selfTypeSource?.fakeElement(FirFakeSourceElementKind.DelegatingConstructorCall) - constructedTypeRef = classWrapper.delegatedSuperTypeRef + constructedTypeRef = classWrapper.delegatedSuperTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) isThis = false extractArgumentsFrom(classWrapper.superTypeCallEntry, stubMode) } @@ -845,7 +845,7 @@ class DeclarationsConverter( } else { constructorDelegationCall.toFirSourceElement() } - constructedTypeRef = delegatedType + constructedTypeRef = delegatedType.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) this.isThis = isThis extractArgumentsFrom(firValueArguments, stubMode) } diff --git a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt index d3a8cf560af..58a4c97ff69 100644 --- a/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt +++ b/compiler/fir/raw-fir/light-tree2fir/src/org/jetbrains/kotlin/fir/lightTree/fir/ValueParameter.kt @@ -5,7 +5,9 @@ package org.jetbrains.kotlin.fir.lightTree.fir +import org.jetbrains.kotlin.fir.FirFakeSourceElementKind import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.copyWithNewSourceKind import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.declarations.FirProperty import org.jetbrains.kotlin.fir.declarations.FirValueParameter @@ -46,7 +48,7 @@ class ValueParameter( source = firValueParameter.source this.session = session origin = FirDeclarationOrigin.Source - returnTypeRef = type + returnTypeRef = type.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) this.name = name initializer = buildQualifiedAccessExpression { calleeReference = buildPropertyFromParameterResolvedNamedReference { diff --git a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt index 5d69edb69a5..6e7063ba576 100644 --- a/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt +++ b/compiler/fir/raw-fir/psi2fir/src/org/jetbrains/kotlin/fir/builder/RawFirBuilder.kt @@ -383,7 +383,7 @@ class RawFirBuilder( source = propertySource session = baseSession origin = FirDeclarationOrigin.Source - returnTypeRef = type + returnTypeRef = type.copyWithNewSourceKind(FirFakeSourceElementKind.PropertyFromParameter) receiverTypeRef = null name = propertyName initializer = buildQualifiedAccessExpression { @@ -597,7 +597,7 @@ class RawFirBuilder( ?: owner.toFirPsiSourceElement(FirFakeSourceElementKind.ImplicitConstructor) val firDelegatedCall = buildDelegatedConstructorCall { source = constructorCallee ?: constructorSource.fakeElement(FirFakeSourceElementKind.DelegatingConstructorCall) - constructedTypeRef = delegatedSuperTypeRef + constructedTypeRef = delegatedSuperTypeRef.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) isThis = false if (!stubMode) { superTypeCallEntry?.extractArgumentsTo(this) @@ -1112,7 +1112,7 @@ class RawFirBuilder( } return buildDelegatedConstructorCall { this.source = source - constructedTypeRef = delegatedType + constructedTypeRef = delegatedType.copyWithNewSourceKind(FirFakeSourceElementKind.ImplicitTypeRef) this.isThis = isThis if (!stubMode) { extractArgumentsTo(this) @@ -1834,11 +1834,11 @@ class RawFirBuilder( override fun visitSuperExpression(expression: KtSuperExpression, data: Unit): FirElement { val superType = expression.superTypeQualifier - val source = expression.toFirSourceElement() + val theSource = expression.toFirSourceElement() return buildQualifiedAccessExpression { - this.source = source + this.source = theSource calleeReference = buildExplicitSuperReference { - source.fakeElement(FirFakeSourceElementKind.ExplicitThisOrSuperReference) + source = theSource.fakeElement(FirFakeSourceElementKind.ExplicitThisOrSuperReference) labelName = expression.getLabelName() superTypeRef = superType.toFirOrImplicitType() } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt index 9104665e55b..7b73a6a39c6 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/ResolveUtils.kt @@ -351,9 +351,14 @@ private fun BodyResolveComponents.typeFromSymbol(symbol: AbstractFirBasedSymbol< if (makeNullable) { returnTypeRef.withReplacedConeType( returnTypeRef.type.withNullability(ConeNullability.NULLABLE, session.typeContext), + FirFakeSourceElementKind.ImplicitTypeRef ) } else { - returnTypeRef + buildResolvedTypeRef { + source = returnTypeRef.source?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef) + type = returnTypeRef.type + annotations += returnTypeRef.annotations + } } } is FirClassifierSymbol<*> -> { diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt index ae3145f57d4..2428f8df7c0 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/FirReceivers.kt @@ -121,3 +121,18 @@ class ImplicitExtensionReceiverValue( useSiteSession: FirSession, scopeSession: ScopeSession ) : ImplicitReceiverValue>(boundSymbol, type, useSiteSession, scopeSession) + + +class InaccessibleImplicitReceiverValue internal constructor( + boundSymbol: FirClassSymbol<*>, + type: ConeKotlinType, + useSiteSession: FirSession, + scopeSession: ScopeSession +) : ImplicitReceiverValue>(boundSymbol, type, useSiteSession, scopeSession) { + internal constructor( + boundSymbol: FirClassSymbol<*>, useSiteSession: FirSession, scopeSession: ScopeSession + ) : this( + boundSymbol, boundSymbol.constructType(typeArguments = emptyArray(), isNullable = false), + useSiteSession, scopeSession + ) +} diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt index a608679a64f..1e6e9865560 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/tower/FirTowerResolverSession.kt @@ -364,8 +364,12 @@ class FirTowerResolverSession internal constructor( onScope(lexical.scope, parentGroup.NonLocal(depth)) } - lexical.implicitReceiver?.let { implicitReceiverValue -> - onImplicitReceiver(implicitReceiverValue, parentGroup.Implicit(depth)) + val receiver = lexical.implicitReceiver + + if (receiver !is InaccessibleImplicitReceiverValue) { + receiver?.let { implicitReceiverValue -> + onImplicitReceiver(implicitReceiverValue, parentGroup.Implicit(depth)) + } } } } 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 c8084e97cd5..765f68e288d 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 @@ -76,6 +76,10 @@ class ConeWrongNumberOfTypeArgumentsError(val desiredCount: Int, val type: FirRe override val reason: String get() = "Wrong number of type arguments" } +class ConeInstanceAccessBeforeSuperCall(val target: String) : ConeDiagnostic() { + override val reason: String get() = "Cannot access ''${target}'' before superclass constructor has been called" +} + private fun describeSymbol(symbol: AbstractFirBasedSymbol<*>): String { return when (symbol) { is FirClassLikeSymbol<*> -> symbol.classId.asString() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 242c4ebe765..76e7136d321 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -88,6 +88,13 @@ class FirCallCompletionResultsWriterTransformer( } } } else { + // this branch is for cases when we have + // some invalid qualified access expression itself. + // e.g. `T::toString` where T is a generic type. + // in these cases we should report an error on + // the calleeReference.source which is not a fake source. + // uncommenting `?.fakeElement...` here removes reports + // of OTHER_ERROR from tests. buildErrorTypeRef { source = calleeReference.source //?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef) diagnostic = ConeSimpleDiagnostic("Callee reference to candidate without return type: ${declaration.render()}") diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt index 758c816962f..31d4b492a3e 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSpecificTypeResolverTransformer.kt @@ -5,9 +5,7 @@ package org.jetbrains.kotlin.fir.resolve.transformers -import org.jetbrains.kotlin.fir.FirSession -import org.jetbrains.kotlin.fir.FirSourceElement -import org.jetbrains.kotlin.fir.PrivateForInline +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirResolvePhase import org.jetbrains.kotlin.fir.diagnostics.ConeUnexpectedTypeArgumentsError import org.jetbrains.kotlin.fir.resolve.typeResolver @@ -69,9 +67,20 @@ class FirSpecificTypeResolverTransformer( } } else { buildErrorTypeRef { - source = resolvedType.diagnostic.safeAs() - ?.source.safeAs() - ?: typeRef.source + val typeRefSourceKind = typeRef.source?.kind + val diagnosticSource = resolvedType.diagnostic.safeAs() + ?.source.safeAs() + + source = if (diagnosticSource != null) { + if (typeRefSourceKind is FirFakeSourceElementKind) { + diagnosticSource.fakeElement(typeRefSourceKind) + } else { + diagnosticSource + } + } else { + typeRef.source + } + diagnostic = resolvedType.diagnostic } }.compose() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 64837822d63..02b2a37329d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -11,7 +11,6 @@ import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.builder.buildValueParameter import org.jetbrains.kotlin.fir.declarations.impl.FirDefaultPropertyAccessor import org.jetbrains.kotlin.fir.declarations.synthetic.FirSyntheticProperty -import org.jetbrains.kotlin.fir.diagnostics.ConeIntermediateDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.* @@ -21,6 +20,7 @@ import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.resolve.* import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate import org.jetbrains.kotlin.fir.resolve.calls.ImplicitExtensionReceiverValue +import org.jetbrains.kotlin.fir.resolve.calls.InaccessibleImplicitReceiverValue import org.jetbrains.kotlin.fir.resolve.dfa.FirControlFlowGraphReferenceImpl import org.jetbrains.kotlin.fir.resolve.inference.FirDelegatedPropertyInferenceSession import org.jetbrains.kotlin.fir.resolve.inference.extractLambdaInfoFromFunctionalType @@ -36,6 +36,7 @@ import org.jetbrains.kotlin.fir.types.builder.buildImplicitTypeRef import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef import org.jetbrains.kotlin.fir.visitors.* import org.jetbrains.kotlin.name.Name +import org.jetbrains.kotlin.utils.addToStdlib.safeAs open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransformer) : FirPartialBodyResolveTransformer(transformer) { private var containingClass: FirRegularClass? = null @@ -550,10 +551,24 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor .transformReceiverTypeRef(transformer, data) .transformReturnTypeRef(transformer, data) + val containers = context.containers + val owningClass = containers[containers.lastIndex - 1].safeAs() + /* * Default values of constructor can't access members of constructing class */ context.withTowerDataContext(context.getTowerDataContextForConstructorResolution()) { + if (owningClass != null && !constructor.isPrimary) { + context.addReceiver( + null, + InaccessibleImplicitReceiverValue( + owningClass.symbol, + owningClass.defaultType(), + session, + scopeSession + ) + ) + } withNewLocalScope { constructor.transformValueParameters(transformer, data) } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 815c7121bef..f264237f7e5 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -75,8 +75,24 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform implicitReceiver?.boundSymbol?.let { callee.replaceBoundSymbol(it) } - qualifiedAccessExpression.resultType = buildResolvedTypeRef { - type = implicitReceiver?.type ?: ConeKotlinErrorType(ConeSimpleDiagnostic("Unresolved this@$labelName", DiagnosticKind.UnresolvedLabel)) + val implicitType = implicitReceiver?.type + qualifiedAccessExpression.resultType = when { + implicitReceiver is InaccessibleImplicitReceiverValue -> buildErrorTypeRef { + source = qualifiedAccessExpression.source + diagnostic = ConeInstanceAccessBeforeSuperCall("") + } + implicitType != null -> buildResolvedTypeRef { + source = callee.source + type = implicitType + } + labelName != null -> buildErrorTypeRef { + source = qualifiedAccessExpression.source + diagnostic = ConeSimpleDiagnostic("Unresolved this@$labelName", DiagnosticKind.UnresolvedLabel) + } + else -> buildErrorTypeRef { + source = qualifiedAccessExpression.source + diagnostic = ConeSimpleDiagnostic("'this' is not defined in this context", DiagnosticKind.NoThis) + } } qualifiedAccessExpression } @@ -312,8 +328,17 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform block.resultType = if (resultExpression == null) { block.resultType.resolvedTypeFromPrototype(session.builtinTypes.unitType.type) } else { - (resultExpression.resultType as? FirResolvedTypeRef) ?: buildErrorTypeRef { - diagnostic = ConeSimpleDiagnostic("No type for block", DiagnosticKind.InferenceError) + val theType = resultExpression.resultType + if (theType is FirResolvedTypeRef) { + buildResolvedTypeRef { + source = theType.source?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef) + type = theType.type + annotations += theType.annotations + } + } else { + buildErrorTypeRef { + diagnostic = ConeSimpleDiagnostic("No type for block", DiagnosticKind.InferenceError) + } } } @@ -489,7 +514,11 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform resolved.resultType = session.builtinTypes.booleanType } FirOperation.AS -> { - resolved.resultType = conversionTypeRef + resolved.resultType = buildResolvedTypeRef { + source = conversionTypeRef.source?.fakeElement(FirFakeSourceElementKind.ImplicitTypeRef) + type = conversionTypeRef.coneType + annotations += conversionTypeRef.annotations + } } FirOperation.SAFE_AS -> { resolved.resultType = @@ -763,9 +792,10 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform when (delegatedConstructorCall.calleeReference) { is FirResolvedNamedReference, is FirErrorNamedReference -> return delegatedConstructorCall.compose() } + val containers = components.context.containers + val containingClass = containers[containers.lastIndex - 1] as FirClass<*> + val containingConstructor = containers.last() as FirConstructor if (delegatedConstructorCall.isSuper && delegatedConstructorCall.constructedTypeRef is FirImplicitTypeRef) { - val containers = components.context.containers - val containingClass = containers[containers.lastIndex - 1] as FirClass<*> val superClass = containingClass.superTypeRefs.firstOrNull { if (it !is FirResolvedTypeRef) return@firstOrNull false val declaration = extractSuperTypeDeclaration(it) ?: return@firstOrNull false @@ -789,7 +819,31 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform context.getPrimaryConstructorParametersScope()?.let(context::addLocalScope) } - delegatedConstructorCall.transformChildren(transformer, ResolutionMode.ContextDependent) + // it's just a constructor parameters scope created in + // `FirDeclarationResolveTransformer::doTransformConstructor()` + val parametersScope = context.towerDataContext.localScopes.lastOrNull() + + // because there's a `context.saveContextForAnonymousFunction(anonymousFunction)` + // call inside of the FirDeclarationResolveTransformer and accessing `this` + // inside a lambda which is a value parameter of a constructor delegate + // is prohibited + context.withTowerDataContext(context.getTowerDataContextForConstructorResolution()) { + parametersScope?.let { + addLocalScope(it) + } + if (containingClass is FirRegularClass && !containingConstructor.isPrimary) { + context.addReceiver( + null, + InaccessibleImplicitReceiverValue( + containingClass.symbol, + containingClass.defaultType(), + session, + scopeSession + ) + ) + } + delegatedConstructorCall.transformChildren(transformer, ResolutionMode.ContextDependent) + } } val reference = delegatedConstructorCall.calleeReference val constructorType: ConeClassLikeType = when (reference) { @@ -814,6 +868,8 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform } } + // it seems that we may leave this code as is + // without adding `context.withTowerDataContext(context.getTowerDataContextForConstructorResolution())` val completionResult = callCompleter.completeCall(resolvedCall, noExpectedType) result = completionResult.result callCompleted = completionResult.callCompleted 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 1a374267361..8c6d4a3fcb6 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 @@ -16,6 +16,7 @@ enum class DiagnosticKind { ReturnNotAllowed, UnresolvedLabel, + NoThis, IllegalConstExpression, IllegalUnderscore, DeserializationError, diff --git a/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.args b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.args new file mode 100644 index 00000000000..c67f1b6ec05 --- /dev/null +++ b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.args @@ -0,0 +1,4 @@ +$TESTDATA_DIR$/instanceAccessBeforeSuperCall.kt +-Xuse-fir +-d +$TEMP_DIR$ \ No newline at end of file diff --git a/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt new file mode 100644 index 00000000000..e185d2123a4 --- /dev/null +++ b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt @@ -0,0 +1,21 @@ +class A { + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + fun getSomeInt() = 10 + var keker = "test" +} + +class B(other: B = this) + +class C() { + constructor(x: Int) : this({ + val a = 10 + this + }) {} +} + +class D { + var a = 20 + constructor() { + this.a = 10 + } +} \ No newline at end of file diff --git a/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out new file mode 100644 index 00000000000..a6d00540672 --- /dev/null +++ b/compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.out @@ -0,0 +1,31 @@ +warning: ATTENTION! +This build uses unsafe internal compiler arguments: + +-XXLanguage:-SoundSmartCastsAfterTry + +This mode is not recommended for production use, +as no stability/compatibility guarantees are given on +compiler or generated code. Use it at your own risk! + +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:26: error: cannot access 'getSomeInt' before superclass constructor has been called + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:51: error: cannot access '' before superclass constructor has been called + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:74: error: cannot access 'keker' before superclass constructor has been called + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:2:74: error: variable 'keker' must be initialized + constructor(x: Int = getSomeInt(), other: A = this, header: String = keker) {} + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:7:20: error: 'this' is not defined in this context +class B(other: B = this) + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:10:32: error: type mismatch: inferred type is () -> C but Int was expected + constructor(x: Int) : this({ + ^ +compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.kt:12:9: error: cannot access '' before superclass constructor has been called + this + ^ +COMPILATION_ERROR diff --git a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt index 0e4171e9987..88ac6c4adcd 100644 --- a/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt +++ b/compiler/testData/diagnostics/tests/EnumEntryAsType.fir.kt @@ -10,14 +10,14 @@ enum class Color { class MyColor(val x: Color.RED, y: Color.RED) : Color.RED { var z: Color.RED = Color.RED - set(arg: Color.RED) { z = arg } + set(arg: Color.RED) { z = arg } fun foo(arg: Color.RED): Color.RED = arg fun bar(): Color.RED { class Local : Color.RED fun local(arg: Color.RED): Color.RED = arg - val temp: Color.RED = Color.RED + val temp: Color.RED = Color.RED temp as? Color.RED if (temp is Color.RED) { return temp as Color.RED diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt b/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt deleted file mode 100644 index 79bbc332054..00000000000 --- a/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.fir.kt +++ /dev/null @@ -1,3 +0,0 @@ -open class A(val x: Any) - -class B : A(this::class) diff --git a/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.kt b/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.kt index 8111828112b..9424852c5a3 100644 --- a/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.kt +++ b/compiler/testData/diagnostics/tests/callableReference/bound/noThisInSuperCall.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL open class A(val x: Any) class B : A(this::class) diff --git a/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt index 3b06d4edfe3..5b5c799c707 100644 --- a/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt +++ b/compiler/testData/diagnostics/tests/cast/bare/ErrorsInSubstitution.fir.kt @@ -3,7 +3,7 @@ interface B interface G: B -fun f(p: B): Any { +fun f(p: B): Any { val v = p as G return checkSubtype>(v) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt b/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt index 8c0af1c54aa..ad882c18bc9 100644 --- a/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt +++ b/compiler/testData/diagnostics/tests/cast/bare/FromErrorType.fir.kt @@ -2,7 +2,7 @@ class G -fun foo(p: P) { +fun foo(p: P) { val v = p as G? checkSubtype>(v!!) } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt index 867811148ad..d55f0669343 100644 --- a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject.fir.kt @@ -15,12 +15,12 @@ fun case_3() { } val x = object> { - fun test() = 10 as T // OK + fun test() = 10 as T // OK } fun case_4() { val x = object { - fun test() = 10 as T + fun test() = 10 as T } val y = x.test() // type y is T diff --git a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt index 98e5b7c9b47..8a5ed8f3ddc 100644 --- a/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt +++ b/compiler/testData/diagnostics/tests/classObjects/typeParametersInAnnonymousObject_after.fir.kt @@ -15,12 +15,12 @@ fun case_3() { } val x = object> { - fun test() = 10 as T // OK + fun test() = 10 as T // OK } fun case_4() { val x = object { - fun test() = 10 as T + fun test() = 10 as T } val y = x.test() // type y is T diff --git a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt index d3c0b59660a..786b23e29f1 100644 --- a/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt +++ b/compiler/testData/diagnostics/tests/collectionLiterals/defaultValuesWithConstantsInAnnotation.fir.kt @@ -21,5 +21,5 @@ annotation class Bar( annotation class Baz( val a: IntArray = [null], val b: IntArray = [1, null, 2], - val c: IntArray = [this] + val c: IntArray = [this] ) diff --git a/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt b/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt index 86c404b813b..e3892b9832e 100644 --- a/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt +++ b/compiler/testData/diagnostics/tests/delegatedProperty/thisInDelegate.fir.kt @@ -2,7 +2,7 @@ import kotlin.reflect.KProperty -val Int.a by Delegate(this) +val Int.a by Delegate(this) class A { val Int.a by Delegate(this) diff --git a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt index c1dbbcefa52..45cb5777982 100644 --- a/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt +++ b/compiler/testData/diagnostics/tests/generics/finalUpperBoundWithoutOverride.fir.kt @@ -59,7 +59,7 @@ class MessageManager11 : Message5>() { fun Message5> execute() {} } -data class MessageManager12(val x: Int) : Message5() { +data class MessageManager12(val x: Int) : Message5() { fun execute() {} } diff --git a/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt index 9abe07a6095..45a84fffb57 100644 --- a/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt +++ b/compiler/testData/diagnostics/tests/incompleteCode/controlStructuresErrors.fir.kt @@ -19,7 +19,7 @@ fun test1() { } } -fun test2(l: List) { +fun test2(l: List) { l.map { it!! } diff --git a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.fir.kt b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.fir.kt index af01f35acc1..0c57ab8574b 100644 --- a/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/completion/postponedArgumentsAnalysis/takingExtensibilityFromDeclarationOfAnonymousFunction.fir.kt @@ -3,6 +3,6 @@ fun id(x: T) = x fun select(vararg x: T) = x[0] -val x1 = select(id { this }, fun Int.() = this) -val x2 = select(id { this + it.inv() }, fun Int.(x: Int) = this) -val x3 = select(id { this.length + it.inv() }, fun String.(x: Int) = length) +val x1 = select(id { this }, fun Int.() = this) +val x2 = select(id { this + it.inv() }, fun Int.(x: Int) = this) +val x3 = select(id { this.length + it.inv() }, fun String.(x: Int) = length) diff --git a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt index 108efe36889..3895321adef 100644 --- a/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/constraints/errorUpperBoundConstraint.fir.kt @@ -19,7 +19,7 @@ public class Foo { // FILE: test.kt -fun test(e: ErrorType) { +fun test(e: ErrorType) { Foo.foo { Sam.Result.create(e) } diff --git a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt index 1e63cd4b0d3..98da1c2d62a 100644 --- a/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt +++ b/compiler/testData/diagnostics/tests/inference/extensionLambdasAndArrow.fir.kt @@ -3,14 +3,14 @@ fun select(vararg x: T) = x[0] fun main() { - val x1: String.() -> String = if (true) {{ this }} else {{ this }} - val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }} + val x1: String.() -> String = if (true) {{ this }} else {{ this }} + val x2: String.() -> String = if (true) {{ -> this }} else {{ -> this }} val x3: () -> String = if (true) {{ -> "this" }} else {{ -> "this" }} val x4: String.() -> String = if (true) {{ str: String -> "this" }} else {{ str: String -> "this" }} val x41: String.(String) -> String = if (true) {{ str: String, str2: String -> "this" }} else {{ str: String, str2: String -> "this" }} val x42: String.(String) -> String = if (true) {{ str, str2 -> "this" }} else {{ str, str2 -> "this" }} val x5: String.() -> String = if (true) {{ str -> "this" }} else {{ str -> "this" }} val x6: String.() -> String = if (true) {{ str -> "this" }} else {{ "this" }} - val x7: String.() -> String = select({ -> this }, { -> this }) - val x8: String.() -> String = select({ this }, { this }) + val x7: String.() -> String = select({ -> this }, { -> this }) + val x8: String.() -> String = select({ this }, { this }) } diff --git a/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt b/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt index a323ecc9ca1..b68718a42e9 100644 --- a/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/innerThisSuper.fir.kt @@ -6,11 +6,11 @@ interface Trait { class Outer : Trait { class Nested { - val t = this@Outer.bar() + val t = this@Outer.bar() val s = super@Outer.bar() inner class NestedInner { - val t = this@Outer.bar() + val t = this@Outer.bar() val s = super@Outer.bar() } } diff --git a/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt b/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt index 7f1c074eb6d..32b4d11d13f 100644 --- a/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt +++ b/compiler/testData/diagnostics/tests/inner/nestedVsInnerAccessOuterMember.fir.kt @@ -7,8 +7,8 @@ class Outer { class Nested { fun f() = function() fun g() = property - fun h() = this@Outer.function() - fun i() = this@Outer.property + fun h() = this@Outer.function() + fun i() = this@Outer.property } inner class Inner { diff --git a/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt index 67361c6adfd..3bdc376abb4 100644 --- a/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt +++ b/compiler/testData/diagnostics/tests/labels/labeledFunctionLiteral.fir.kt @@ -1,17 +1,17 @@ // !DIAGNOSTICS: -UNUSED_VARIABLE val funLit = lambda@ fun String.() { - val d1 = this@lambda + val d1 = this@lambda } fun test() { val funLit = lambda@ fun String.(): String { - return this@lambda + return this@lambda } } fun lambda() { val funLit = lambda@ fun String.(): String { - return this@lambda + return this@lambda } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt b/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt index 49cf7add2a6..f63947415dc 100644 --- a/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/UnavaliableQualifiedThis.fir.kt @@ -4,10 +4,10 @@ interface Iterator { fun map(transform: (element: T) -> R) : Iterator = object : Iterator { - override fun next() : R = transform(this@map.next()) + override fun next() : R = transform(this@map.next()) override val hasNext : Boolean // There's no 'this' associated with the map() function, only this of the Iterator class - get() = this@map.hasNext + get() = this@map.hasNext } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt index 436c654e577..fb127e776dd 100644 --- a/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt +++ b/compiler/testData/diagnostics/tests/regressions/kt30245.fir.kt @@ -39,8 +39,8 @@ class W4(val f: L2) { fun test1() { // to extension lambda 0 val w10 = W1 { this } // oi+ ni+ - val i10: E0 = id { this } // o1- ni+ - val j10 = id { this } // oi+ ni+ + val i10: E0 = id { this } // o1- ni+ + val j10 = id { this } // oi+ ni+ val f10 = W1(fun Int.(): Int = this) // oi+ ni+ val g10: E0 = id(fun Int.(): Int = this) // oi+ ni+ @@ -60,28 +60,28 @@ fun test1() { // to extension lambda 0 fun test2() { // to extension lambda 1 val w20 = W2 { this + it.length } // oi+ ni+ - val i20: E1 = id { this + it.length } // oi- ni+ + val i20: E1 = id { this + it.length } // oi- ni+ val w21 = W2 { this } // oi+ ni+ - val i21: E1 = id { this } // oi- ni+ + val i21: E1 = id { this } // oi- ni+ val f21 = W2(fun Int.(String): Int = this) // oi+ ni+ val g21: E1 = id(fun Int.(String): Int = this) // oi+ ni+ val w22 = W2 { s -> this + s.length } // oi+ ni+ - val i22: E1 = id { s -> this + s.length } // oi+ ni+ + val i22: E1 = id { s -> this + s.length } // oi+ ni+ val w23 = W2 { s -> s.length } // oi+ ni+ val i23: E1 = id { s -> s.length } // oi+ ni+ val w24 = W2 { s: String -> this + s.length } // oi+ ni+ - val i24: E1 = id { s: String -> this + s.length } //oi- ni+ + val i24: E1 = id { s: String -> this + s.length } //oi- ni+ val w25 = W2 { s: String -> s.length } // oi+ ni+ val i25: E1 = id { s: String -> s.length } // oi- ni+ - val w26 = W2(id { s: String -> this + s.length }) // oi- ni+ - val w26a = W2(id { s -> this + s.length }) // oi+ ni+ - val i26: E1 = id { s: String -> this + s.length } // oi- ni+ - val i26a: E1 = id { s -> this + s.length } // oi+ ni+ + val w26 = W2(id { s: String -> this + s.length }) // oi- ni+ + val w26a = W2(id { s -> this + s.length }) // oi+ ni+ + val i26: E1 = id { s: String -> this + s.length } // oi- ni+ + val i26a: E1 = id { s -> this + s.length } // oi+ ni+ val e = E.VALUE - val w27 = W2(when (e) { E.VALUE -> { s: String -> this + s.length } }) // oi- ni+ - val w27a = W2(when (e) { E.VALUE -> { s -> this + s.length } }) // oi+ ni+ - val i27: E1 = when (e) { E.VALUE -> { s: String -> this + s.length } } // oi+ ni+ - val i27a: E1 = when (e) { E.VALUE -> { s -> this + s.length } } // oi+ ni+ + val w27 = W2(when (e) { E.VALUE -> { s: String -> this + s.length } }) // oi- ni+ + val w27a = W2(when (e) { E.VALUE -> { s -> this + s.length } }) // oi+ ni+ + val i27: E1 = when (e) { E.VALUE -> { s: String -> this + s.length } } // oi+ ni+ + val i27a: E1 = when (e) { E.VALUE -> { s -> this + s.length } } // oi+ ni+ val w28 = W2 { i: Int, s -> i + s.length } // oi- ni- val i28: E1 = id { i: Int, s -> i + s.length } // oi- ni- diff --git a/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt b/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt deleted file mode 100644 index 8530a32e330..00000000000 --- a/compiler/testData/diagnostics/tests/regressions/noThis.fir.kt +++ /dev/null @@ -1,10 +0,0 @@ -interface A { fun f() } - -open class P(val z: B) - -class B : A { - override fun f() {} - class C : A by this {} - class D(val x : B = this) - class E : P(this) -} \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/regressions/noThis.kt b/compiler/testData/diagnostics/tests/regressions/noThis.kt index b63745531ba..39c581abaa8 100644 --- a/compiler/testData/diagnostics/tests/regressions/noThis.kt +++ b/compiler/testData/diagnostics/tests/regressions/noThis.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL interface A { fun f() } open class P(val z: B) diff --git a/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt b/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt index d7f9a6bfdc3..b4f39e24de8 100644 --- a/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt +++ b/compiler/testData/diagnostics/tests/resolve/ambiguityWithTwoCorrespondingFunctionTypes.fir.kt @@ -6,6 +6,6 @@ fun foo(i: Int, f: Int.()->Int) = i.f() fun test1() { foo(1) { -> - this + this } } diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt index ca57c76425b..144e13eba52 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/constructors.fir.kt @@ -37,8 +37,8 @@ class A( Companion.CONST, Nested.CONST, Interface.CONST, - a, - b() + a, + b() ) class Nested { diff --git a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt index a80d7a560de..065b7f95d9c 100644 --- a/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/classHeader/superConstructorArgumentsInSecondaryConstructor.fir.kt @@ -22,8 +22,8 @@ class A : S { Companion.CONST, Nested.CONST, Interface.CONST, - a, - b() + a, + b() ) class Nested { diff --git a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt index acf064229ea..f1227579248 100644 --- a/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/initializerScopeOfExtensionProperty.fir.kt @@ -6,7 +6,7 @@ val List.length = size val List.length1 : Int get() = size -val String.bd = this + "!" +val String.bd = this + "!" val String.bd1 : String get() = this + "!" diff --git a/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt b/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt index 0b64ce516e5..d6dabb1ead3 100644 --- a/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt +++ b/compiler/testData/diagnostics/tests/scopes/kt250.617.10.fir.kt @@ -31,7 +31,7 @@ open class BodyTag(name : String) : TagWithText(name) { class Body() : BodyTag(name) { // Must be an error! } -class Body1() : BodyTag(this.name) { // Must be an error! +class Body1() : BodyTag(this.name) { // Must be an error! } //more tests diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt index 84fbd66adf9..d3a39f171e3 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase.fir.kt @@ -6,7 +6,7 @@ open class Base(p: Any?) { class D: Base("") { inner class B : Base { - constructor() : super(foo1("")) + constructor() : super(foo1("")) constructor(x: Int) : super(foo1(1)) } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt index 4e0acde4f71..6420ae5e373 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseGenericFromInnerExtendingSameBase2.fir.kt @@ -7,7 +7,7 @@ open class Base(p: Any?) { class D: Base(1) { inner class B : Base { constructor() : super(foo1(1)) - constructor(x: Int) : super(this@B.foo1(1)) + constructor(x: Int) : super(this@B.foo1(1)) constructor(x: Int, y: Int) : super(this@D.foo1(1)) } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt index c5340674800..30f118d048b 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessBaseWithSameExtension.fir.kt @@ -7,6 +7,6 @@ fun Base.foo() { class B : Base { constructor() : super(foo1()) constructor(x: Int) : super(this@foo.foo1()) - constructor(x: Int, y: Int) : super(this@B.foo1()) + constructor(x: Int, y: Int) : super(this@B.foo1()) } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt index a45e891e7e1..2c1c4ad9613 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/accessGenericBaseWithSameExtension.fir.kt @@ -5,9 +5,9 @@ open class Base(p: Any?) { fun Base.foo() { class B : Base { - constructor() : super(foo1("")) + constructor() : super(foo1("")) constructor(x: Int) : super(foo1(1)) constructor(x: Int, y: Int) : super(this@foo.foo1(12)) - constructor(x: Int, y: Int, z: Int) : super(this@B.foo1("")) + constructor(x: Int, y: Int, z: Int) : super(this@B.foo1("")) } } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt index 225107d83e4..690acf8d810 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/innerInstanceCreation.fir.kt @@ -6,6 +6,6 @@ class Outer { } constructor(x: Int) - constructor(x: Int, y: Int, z: Int = x + Inner().prop + this.Inner().prop) : - this(x + Inner().prop + this.Inner().prop) + constructor(x: Int, y: Int, z: Int = x + Inner().prop + this.Inner().prop) : + this(x + Inner().prop + this.Inner().prop) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt index 1a01acc6fb0..46441fff1a9 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/lambdaAsArgument.fir.kt @@ -7,9 +7,9 @@ class A { constructor(x: () -> Int) constructor() : this( { - foo() + - this.foo() + - this@A.foo() + - foobar() + foo() + + this.foo() + + this@A.foo() + + foobar() }) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt index 1b6fb0bafca..dece2048ae4 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/memberFunAccess.fir.kt @@ -2,6 +2,6 @@ class A { fun foo() = 1 constructor(x: Int) - constructor(x: Int, y: Int, z: Int = x + foo() + this.foo()) : - this(x + foo() + this.foo()) + constructor(x: Int, y: Int, z: Int = x + foo() + this.foo()) : + this(x + foo() + this.foo()) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt index dd0522dc156..1f459e5612a 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsArgument.fir.kt @@ -6,7 +6,7 @@ class A { fun foo() = 1 constructor(x: Any?) constructor() : this(object { - fun bar() = foo() + this@A.foo() + - foobar() + super@A.hashCode() + fun bar() = foo() + this@A.foo() + + foobar() + super@A.hashCode() }) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt index 360383e4cd0..c490b9d3b52 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/objectLiteralAsDefaultValueParameter.fir.kt @@ -5,7 +5,7 @@ fun A.foobar() = 3 class A { fun foo() = 1 constructor( x: Any = object { - fun bar() = foo() + this@A.foo() + + fun bar() = foo() + this@A.foo() + foobar() }) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt index adc3dd248dc..6f999a9d56c 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/operatorCall.fir.kt @@ -4,8 +4,8 @@ class D : C { constructor() : super( { val s = "" - s() - ""() + s() + ""() 42 }()) diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt index 8fe392bd885..293fc00a6c4 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/passingInstance.fir.kt @@ -3,6 +3,6 @@ fun foo(x: A) = 1 class A { constructor(x: Int) - constructor(x: Int, y: Int, z: Int = x + foo(this) + foo(this@A)) : - this(x + foo(this) + foo(this@A)) + constructor(x: Int, y: Int, z: Int = x + foo(this) + foo(this@A)) : + this(x + foo(this) + foo(this@A)) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt index 976392d5903..1bfa4b4cb08 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccess.fir.kt @@ -2,6 +2,6 @@ class A { val prop = 1 constructor(x: Int) - constructor(x: Int, y: Int, z: Int = x + prop + this.prop) : - this(x + prop + this.prop) + constructor(x: Int, y: Int, z: Int = x + prop + this.prop) : + this(x + prop + this.prop) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt index 5435edb16d5..72465299653 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/propertyAccessUnitialized.fir.kt @@ -2,6 +2,6 @@ open class B(x: Int) class A : B { val prop = 1 - constructor(x: Int, y: Int = x + prop + this.prop) : - super(x + prop + this.prop) + constructor(x: Int, y: Int = x + prop + this.prop) : + super(x + prop + this.prop) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt index 5637a70edd0..f301b0054c8 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccess.fir.kt @@ -3,6 +3,6 @@ open class B(x: Int) { fun foo() = 1 } class A : B { - constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : - super(x + foo() + this.foo() + super.foo()) + constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : + super(x + foo() + this.foo() + super.foo()) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt index b24de18ef54..9af9f94d508 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superFunAccessOverriden.fir.kt @@ -4,6 +4,6 @@ open class B(x: Int) { } class A : B { override fun foo() = 2 - constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : - super(x + foo() + this.foo() + super.foo()) + constructor(x: Int, y: Int = x + foo() + this.foo() + super.foo()) : + super(x + foo() + this.foo() + super.foo()) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt index b608709e4b5..3162eb46624 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/superPropertyAccess.fir.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER open class B(val prop: Int) class A : B { - constructor(x: Int, y: Int = x + prop + this.prop + super.prop) : - super(x + prop + this.prop + super.prop) + constructor(x: Int, y: Int = x + prop + this.prop + super.prop) : + super(x + prop + this.prop + super.prop) } diff --git a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt index 67d31be0d8a..888899be4f8 100644 --- a/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt +++ b/compiler/testData/diagnostics/tests/secondaryConstructors/headerCallChecker/thisAsExtensionReceiver.fir.kt @@ -5,11 +5,11 @@ val A.prop: Int get() = 2 class A { constructor(x: Int) - constructor() : this( - foobar() + - this.foobar() + - prop + - this.prop + - this@A.prop + constructor() : this( + foobar() + + this.foobar() + + prop + + this.prop + + this@A.prop ) } diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt index f6a01a8db89..b9acf2d4078 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/QualifiedThis.fir.kt @@ -2,7 +2,7 @@ class A() { fun foo() : Unit { this@A - this@a + this@a this } diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt index 225d2282096..801ab918912 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInFunctionLiterals.fir.kt @@ -11,7 +11,7 @@ class A(val a:Int) { checkSubtype(this@A) } val b: Double.() -> Unit = a@{ checkSubtype(this@a) + checkSubtype(this@xx) } - val c = a@{ -> this@a + checkSubtype(this@xx) } + val c = a@{ -> this@a + checkSubtype(this@xx) } return (a@{checkSubtype(this@a) + checkSubtype(this@xx)}) } } diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt index 007d6e065bc..32037c0a692 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInPropertyInitializer.fir.kt @@ -3,6 +3,6 @@ interface Base { } val String.test: Base = object: Base { override fun foo() { - this@test + this@test } } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt index 34e17b1c77e..c8dc08dba0b 100644 --- a/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt +++ b/compiler/testData/diagnostics/tests/thisAndSuper/thisInToplevelFunction.fir.kt @@ -1,4 +1,4 @@ fun foo1() : Unit { - this - this@a + this + this@a } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt index 426a57db05d..5d4051e26f2 100644 --- a/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/inhreritedTypeAliasQualifiedByDerivedClass.fir.kt @@ -6,8 +6,8 @@ open class Base { class Derived : Base() -fun test(x: Derived.Nested) = x +fun test(x: Derived.Nested) = x -fun Base.testWithImplicitReceiver(x: Nested) { +fun Base.testWithImplicitReceiver(x: Nested) { val y: Nested = x } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt index cfc76a6ec91..cc100a53247 100644 --- a/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/innerTypeAliasAsType.fir.kt @@ -11,12 +11,12 @@ class Outer { typealias InnerAlias = Inner typealias GenericInnerAlias = GenericInner - fun test1(x: NestedAlias) = x - fun test2(x: GenericNestedAlias) = x - fun test3(x: GenericNestedAlias) = x - fun test4(x: InnerAlias) = x - fun test5(x: GenericInnerAlias) = x - fun test6(x: GenericInnerAlias) = x + fun test1(x: NestedAlias) = x + fun test2(x: GenericNestedAlias) = x + fun test3(x: GenericNestedAlias) = x + fun test4(x: InnerAlias) = x + fun test5(x: GenericInnerAlias) = x + fun test6(x: GenericInnerAlias) = x } fun test1(x: Outer.NestedAlias) = x fun test2(x: Outer.NestedAlias) = x diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt index 080b05dc681..ee1ea1d2aba 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAlias.fir.kt @@ -5,12 +5,12 @@ fun emptyList(): List = null!! fun foo() { typealias LT = List - val a: LT = emptyList() + val a: LT = emptyList() fun localFun(): LT { typealias LLT = List - val b: LLT = a + val b: LLT = a return b } diff --git a/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt index 38f13e74a8c..749a5c6c84d 100644 --- a/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/localTypeAliasConstructor.fir.kt @@ -4,8 +4,8 @@ class Cell(val x: TC) fun id(x: T): T { typealias C = Cell - class Local(val cell: C) + class Local(val cell: C) val cx = C(x) - val c: C = Local(cx).cell + val c: C = Local(cx).cell return c.x } diff --git a/compiler/testData/diagnostics/tests/typealias/nested.fir.kt b/compiler/testData/diagnostics/tests/typealias/nested.fir.kt index 41afad62d21..4e49e8fa406 100644 --- a/compiler/testData/diagnostics/tests/typealias/nested.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/nested.fir.kt @@ -6,8 +6,8 @@ class C { typealias P2 = Pair fun p() = P2(1, 1) - fun first(p: P2) = p.x1 - fun second(p: P2) = p.x2 + fun first(p: P2) = p.x1 + fun second(p: P2) = p.x2 } val p1 = Pair(1, 1) diff --git a/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt index 24b31359ab4..cb145353a7c 100644 --- a/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt +++ b/compiler/testData/diagnostics/tests/typealias/nestedCapturingTypeParameters.fir.kt @@ -6,11 +6,11 @@ class C { typealias P2 = Pair typealias PT2 = Pair - fun first(p: P2) = p.x1 - fun second(p: P2) = p.x2 + fun first(p: P2) = p.x1 + fun second(p: P2) = p.x2 - fun first2(p: PT2) = p.x1 - fun second2(p: PT2) = p.x2 + fun first2(p: PT2) = p.x1 + fun second2(p: PT2) = p.x2 } val p1 = Pair(1, 1) diff --git a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/accessToOuterThis.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/accessToOuterThis.fir.kt index 8407b8e1afd..dff2d7c2e5f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/accessToOuterThis.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/contracts/dsl/errors/accessToOuterThis.fir.kt @@ -10,13 +10,13 @@ class Foo { inner class Bar { fun good() { contract { - returns() implies (this@Bar != null) + returns() implies (this@Bar != null) } } fun badOuter() { contract { - returns() implies (this@Foo != null) + returns() implies (this@Foo != null) } } @@ -34,7 +34,7 @@ class Foo { fun A?.badWithReceiver() { contract { - returns() implies (this@Bar != null) + returns() implies (this@Bar != null) } } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt index 1128663eb10..ec428e324d1 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/coroutines/callableReference/callableReferenceOnUnresolvedLHS.fir.kt @@ -3,7 +3,7 @@ interface Inv class Impl : Inv -class Scope(private val implClass: j.Class) { +class Scope(private val implClass: j.Class) { fun foo(c: Collection) { val hm = c.asSequence() .filter(implClass::isInstance) diff --git a/compiler/testData/diagnostics/testsWithStdLib/regression/kt37727.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/regression/kt37727.fir.kt index 40dcbb2bb67..72ea6639c4f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/regression/kt37727.fir.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/regression/kt37727.fir.kt @@ -1,5 +1,5 @@ -data class A(val x: Set = setOf()) { - fun with(x: Set? = null) { +data class A(val x: Set = setOf()) { + fun with(x: Set? = null) { A(x ?: this.x) } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt index 664983781cc..76c8939d1d7 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/contracts/declarations/contractFunction/neg/2.fir.kt @@ -32,7 +32,7 @@ fun case_2() { class case_4 : ClassLevel3() { fun T.case_4_1(): Boolean { - contract { returns(false) implies (this@case_4 !is ClassLevel1) } + contract { returns(false) implies (this@case_4 !is ClassLevel1) } return this == null } @@ -60,12 +60,12 @@ class case_4 : ClassLevel3() { class case_5 : ClassLevel5() { inner class case_5_1 { fun K.case_5_1_1() { - contract { returns() implies (this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this@case_5_1_1 is Float) } + contract { returns() implies (this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this@case_5_1_1 is Float) } if (!(this@case_5_1 !is ClassLevel1 && this@case_5_1 != null || this@case_5 is ClassLevel1 && this is Float)) throw Exception() } fun case_5_1_2() { - contract { returns() implies (this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null) } + contract { returns() implies (this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null) } if (!(this@case_5_1 !is ClassLevel1 || this@case_5 is ClassLevel1 || this@case_5_1 == null)) throw Exception() } } diff --git a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt index d901325f764..a1a07494265 100644 --- a/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt +++ b/compiler/tests-spec/testData/diagnostics/notLinked/dfa/neg/1.fir.kt @@ -179,7 +179,7 @@ fun case_12(x: TypealiasNullableStringIndirect, y: TypealiasNullableStringIndire else "-1" // TESTCASE NUMBER: 13 -fun case_13(x: otherpackage.Case13?) = +fun case_13(x: otherpackage.Case13?) = if ((x == null !is Boolean) !== true) { throw Exception() } else { @@ -189,7 +189,7 @@ fun case_13(x: otherpackage.Case14? + val x: otherpackage.Case14? init { x = otherpackage.Case14() } diff --git a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java index 39cc87145a9..7388b2e5dfa 100644 --- a/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/cli/CliTestGenerated.java @@ -335,6 +335,11 @@ public class CliTestGenerated extends AbstractCliTest { runTest("compiler/testData/cli/jvm/inlineCycle_ir.args"); } + @TestMetadata("instanceAccessBeforeSuperCall.args") + public void testInstanceAccessBeforeSuperCall() throws Exception { + runTest("compiler/testData/cli/jvm/instanceAccessBeforeSuperCall.args"); + } + @TestMetadata("internalArgDisableLanguageFeature.args") public void testInternalArgDisableLanguageFeature() throws Exception { runTest("compiler/testData/cli/jvm/internalArgDisableLanguageFeature.args");