From 1c9064836e2b30dd63fddc68c40a0ca926c1e422 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 22 Jan 2021 09:00:32 +0300 Subject: [PATCH] FIR2IR: fix intersection type smart cast when synthetic property accessed --- .../runners/ir/Fir2IrTextTestGenerated.java | 6 + .../fir/backend/Fir2IrImplicitCastInserter.kt | 20 +++ .../ir/irText/firProblems/Modality.fir.kt.txt | 70 ++++++++ .../ir/irText/firProblems/Modality.fir.txt | 168 +++++++++++++++++ .../ir/irText/firProblems/Modality.kt | 49 +++++ .../ir/irText/firProblems/Modality.kt.txt | 72 ++++++++ .../ir/irText/firProblems/Modality.txt | 169 ++++++++++++++++++ .../test/runners/ir/IrTextTestGenerated.java | 6 + 8 files changed, 560 insertions(+) create mode 100644 compiler/testData/ir/irText/firProblems/Modality.fir.kt.txt create mode 100644 compiler/testData/ir/irText/firProblems/Modality.fir.txt create mode 100644 compiler/testData/ir/irText/firProblems/Modality.kt create mode 100644 compiler/testData/ir/irText/firProblems/Modality.kt.txt create mode 100644 compiler/testData/ir/irText/firProblems/Modality.txt diff --git a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 7271c45b46c..4fea51d67d7 100644 --- a/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/analysis-tests/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2146,6 +2146,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/firProblems/kt43342.kt"); } + @Test + @TestMetadata("Modality.kt") + public void testModality() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/Modality.kt"); + } + @Test @TestMetadata("MultiList.kt") public void testMultiList() throws Exception { diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt index 860d2ae6d02..2eced88dafa 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrImplicitCastInserter.kt @@ -16,8 +16,11 @@ import org.jetbrains.kotlin.fir.expressions.impl.FirUnitExpression import org.jetbrains.kotlin.fir.references.FirReference import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.render +import org.jetbrains.kotlin.fir.resolve.calls.FirSyntheticPropertiesScope +import org.jetbrains.kotlin.fir.resolve.calls.SyntheticPropertySymbol import org.jetbrains.kotlin.fir.resolve.scope import org.jetbrains.kotlin.fir.scopes.FakeOverrideTypeCalculator +import org.jetbrains.kotlin.fir.scopes.FirTypeScope import org.jetbrains.kotlin.fir.symbols.AbstractFirBasedSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol @@ -326,6 +329,9 @@ class Fir2IrImplicitCastInserter( referencedSymbol: AbstractFirBasedSymbol<*>, name: Name ): Boolean { val scope = scope(session, components.scopeSession, FakeOverrideTypeCalculator.Forced) ?: return false + if (referencedSymbol is SyntheticPropertySymbol) { + return doesContainReferencedSyntheticSymbolInScope(referencedSymbol, name, scope) + } var result = false val processor = { it: FirCallableSymbol<*> -> if (!result && it == referencedSymbol) { @@ -339,6 +345,20 @@ class Fir2IrImplicitCastInserter( return result } + private fun doesContainReferencedSyntheticSymbolInScope( + referencedSymbol: SyntheticPropertySymbol, name: Name, baseScope: FirTypeScope + ): Boolean { + val scope = FirSyntheticPropertiesScope(session, baseScope) + var result = false + val processor = { it: FirCallableSymbol<*> -> + if (!result && it.callableId == referencedSymbol.callableId) { + result = true + } + } + scope.processPropertiesByName(name, processor) + return result + } + private fun implicitCastOrExpression(original: IrExpression, castType: ConeKotlinType): IrExpression { return implicitCastOrExpression(original, castType.toIrType()) } diff --git a/compiler/testData/ir/irText/firProblems/Modality.fir.kt.txt b/compiler/testData/ir/irText/firProblems/Modality.fir.kt.txt new file mode 100644 index 00000000000..1c132ca400a --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/Modality.fir.kt.txt @@ -0,0 +1,70 @@ +interface Substitutable { + +} + +abstract class ResolutionPart { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun KotlinResolutionCandidate.process(): String + +} + +class KotlinResolutionCandidate { + constructor(resolvedCall: Atom) /* primary */ { + super/*Any*/() + /* () */ + + } + + val resolvedCall: Atom + field = resolvedCall + get + +} + +class Atom { + constructor(candidateDescriptor: CallableDescriptor) /* primary */ { + super/*Any*/() + /* () */ + + } + + val candidateDescriptor: CallableDescriptor + field = candidateDescriptor + get + +} + +object Owner : ResolutionPart { + private constructor() /* primary */ { + super/*ResolutionPart*/() + /* () */ + + } + + override fun KotlinResolutionCandidate.process(): String { + val candidateDescriptor: CallableDescriptor = .().() + when { + when { + candidateDescriptor is MemberDescriptor -> EQEQ(arg0 = candidateDescriptor /*as MemberDescriptor */.getModality(), arg1 = null).not() + else -> false + } -> return "OK" + } + return "FAIL" + } + +} + +object Final : Modality { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + diff --git a/compiler/testData/ir/irText/firProblems/Modality.fir.txt b/compiler/testData/ir/irText/firProblems/Modality.fir.txt new file mode 100644 index 00000000000..7a33c3b4ced --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/Modality.fir.txt @@ -0,0 +1,168 @@ +FILE fqName: fileName:/Modality.kt + CLASS INTERFACE name:Substitutable modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Substitutable.Substitutable> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[.DeclarationDescriptorNonRoot] + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.ResolutionPart + CONSTRUCTOR visibility:public <> () returnType:.ResolutionPart [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any]' + FUN name:process visibility:public modality:ABSTRACT <> ($this:.ResolutionPart, $receiver:.KotlinResolutionCandidate) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.ResolutionPart + $receiver: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.KotlinResolutionCandidate + CONSTRUCTOR visibility:public <> (resolvedCall:.Atom) returnType:.KotlinResolutionCandidate [primary] + VALUE_PARAMETER name:resolvedCall index:0 type:.Atom + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:resolvedCall visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:.Atom visibility:private [final] + EXPRESSION_BODY + GET_VAR 'resolvedCall: .Atom declared in .KotlinResolutionCandidate.' type=.Atom origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.KotlinResolutionCandidate) returnType:.Atom + correspondingProperty: PROPERTY name:resolvedCall visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .Atom declared in .KotlinResolutionCandidate' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:.Atom visibility:private [final]' type=.Atom origin=null + receiver: GET_VAR ': .KotlinResolutionCandidate declared in .KotlinResolutionCandidate.' type=.KotlinResolutionCandidate origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Atom + CONSTRUCTOR visibility:public <> (candidateDescriptor:.CallableDescriptor) returnType:.Atom [primary] + VALUE_PARAMETER name:candidateDescriptor index:0 type:.CallableDescriptor + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:.CallableDescriptor visibility:private [final] + EXPRESSION_BODY + GET_VAR 'candidateDescriptor: .CallableDescriptor declared in .Atom.' type=.CallableDescriptor origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Atom) returnType:.CallableDescriptor + correspondingProperty: PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Atom + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .CallableDescriptor declared in .Atom' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:.CallableDescriptor visibility:private [final]' type=.CallableDescriptor origin=null + receiver: GET_VAR ': .Atom declared in .Atom.' type=.Atom origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[.ResolutionPart] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner + CONSTRUCTOR visibility:private <> () returnType:.Owner [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .ResolutionPart' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[.ResolutionPart]' + FUN name:process visibility:public modality:FINAL <> ($this:.Owner, $receiver:.KotlinResolutionCandidate) returnType:kotlin.String + overridden: + public abstract fun process (): kotlin.String declared in .ResolutionPart + $this: VALUE_PARAMETER name: type:.Owner + $receiver: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + BLOCK_BODY + VAR name:candidateDescriptor type:.CallableDescriptor [val] + CALL 'public final fun (): .CallableDescriptor declared in .Atom' type=.CallableDescriptor origin=GET_PROPERTY + $this: CALL 'public final fun (): .Atom declared in .KotlinResolutionCandidate' type=.Atom origin=GET_PROPERTY + $this: GET_VAR ': .KotlinResolutionCandidate declared in .Owner.process' type=.KotlinResolutionCandidate origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: WHEN type=kotlin.Boolean origin=ANDAND + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.MemberDescriptor + GET_VAR 'val candidateDescriptor: .CallableDescriptor [val] declared in .Owner.process' type=.CallableDescriptor origin=null + then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL 'public abstract fun getModality (): .Modality? declared in .MemberDescriptor' type=.Modality? origin=GET_PROPERTY + $this: TYPE_OP type=.MemberDescriptor origin=IMPLICIT_CAST typeOperand=.MemberDescriptor + GET_VAR 'val candidateDescriptor: .CallableDescriptor [val] declared in .Owner.process' type=.CallableDescriptor origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST Boolean type=kotlin.Boolean value=false + then: RETURN type=kotlin.Nothing from='public final fun process (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="OK" + RETURN type=kotlin.Nothing from='public final fun process (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="FAIL" + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[.Modality] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Final + CONSTRUCTOR visibility:private <> () returnType:.Final [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[.Modality]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/testData/ir/irText/firProblems/Modality.kt b/compiler/testData/ir/irText/firProblems/Modality.kt new file mode 100644 index 00000000000..d5cbb558db9 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/Modality.kt @@ -0,0 +1,49 @@ +// FILE: Modality.java +public interface Modality + +// FILE: DeclarationDescriptor.java +public interface DeclarationDescriptor + +// FILE: DeclarationDescriptorWithVisibility.java +public interface DeclarationDescriptorWithVisibility extends DeclarationDescriptor + +// FILE: DeclarationDescriptorWithSource.java +public interface DeclarationDescriptorWithSource extends DeclarationDescriptor + +// FILE: DeclarationDescriptorNonRoot.java +public interface DeclarationDescriptorNonRoot extends DeclarationDescriptorWithSource + +// FILE: CallableDescriptor.java +public interface CallableDescriptor extends +DeclarationDescriptorWithVisibility, DeclarationDescriptorNonRoot, Substitutable + +// FILE: MemberDescriptor.java +public interface MemberDescriptor extends DeclarationDescriptorNonRoot, DeclarationDescriptorWithVisibility { + Modality getModality(); +} + +// FILE: Modality.kt +interface Substitutable + +abstract class ResolutionPart { + abstract fun KotlinResolutionCandidate.process(): String + + // helper functions + //protected inline val KotlinResolutionCandidate.candidateDescriptor get() = resolvedCall.candidateDescriptor +} + +class KotlinResolutionCandidate(val resolvedCall: Atom) + +class Atom(val candidateDescriptor: CallableDescriptor) + +object Owner : ResolutionPart() { + override fun KotlinResolutionCandidate.process(): String { + val candidateDescriptor = resolvedCall.candidateDescriptor + if (candidateDescriptor is MemberDescriptor && candidateDescriptor.modality != null) { + return "OK" + } + return "FAIL" + } +} + +object Final : Modality diff --git a/compiler/testData/ir/irText/firProblems/Modality.kt.txt b/compiler/testData/ir/irText/firProblems/Modality.kt.txt new file mode 100644 index 00000000000..702b7267db8 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/Modality.kt.txt @@ -0,0 +1,72 @@ +interface Substitutable { + +} + +abstract class ResolutionPart { + constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + + abstract fun KotlinResolutionCandidate.process(): String + +} + +class KotlinResolutionCandidate { + constructor(resolvedCall: Atom) /* primary */ { + super/*Any*/() + /* () */ + + } + + val resolvedCall: Atom + field = resolvedCall + get + +} + +class Atom { + constructor(candidateDescriptor: CallableDescriptor) /* primary */ { + super/*Any*/() + /* () */ + + } + + val candidateDescriptor: CallableDescriptor + field = candidateDescriptor + get + +} + +object Owner : ResolutionPart { + private constructor() /* primary */ { + super/*ResolutionPart*/() + /* () */ + + } + + override fun KotlinResolutionCandidate.process(): String { + val candidateDescriptor: CallableDescriptor = .().() + when { + when { + candidateDescriptor is MemberDescriptor -> EQEQ(arg0 = candidateDescriptor /*as MemberDescriptor */.getModality(), arg1 = null).not() + else -> false + } -> { // BLOCK + return "OK" + } + } + return "FAIL" + } + +} + +object Final : Modality { + private constructor() /* primary */ { + super/*Any*/() + /* () */ + + } + +} + diff --git a/compiler/testData/ir/irText/firProblems/Modality.txt b/compiler/testData/ir/irText/firProblems/Modality.txt new file mode 100644 index 00000000000..bf006084354 --- /dev/null +++ b/compiler/testData/ir/irText/firProblems/Modality.txt @@ -0,0 +1,169 @@ +FILE fqName: fileName:/Modality.kt + CLASS INTERFACE name:Substitutable modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Substitutable.Substitutable> + TYPE_PARAMETER name:T index:0 variance:out superTypes:[.DeclarationDescriptorNonRoot] + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.ResolutionPart + CONSTRUCTOR visibility:public <> () returnType:.ResolutionPart [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:ResolutionPart modality:ABSTRACT visibility:public superTypes:[kotlin.Any]' + FUN name:process visibility:public modality:ABSTRACT <> ($this:.ResolutionPart, $receiver:.KotlinResolutionCandidate) returnType:kotlin.String + $this: VALUE_PARAMETER name: type:.ResolutionPart + $receiver: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.KotlinResolutionCandidate + CONSTRUCTOR visibility:public <> (resolvedCall:.Atom) returnType:.KotlinResolutionCandidate [primary] + VALUE_PARAMETER name:resolvedCall index:0 type:.Atom + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:KotlinResolutionCandidate modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:resolvedCall visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:.Atom visibility:private [final] + EXPRESSION_BODY + GET_VAR 'resolvedCall: .Atom declared in .KotlinResolutionCandidate.' type=.Atom origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.KotlinResolutionCandidate) returnType:.Atom + correspondingProperty: PROPERTY name:resolvedCall visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .Atom declared in .KotlinResolutionCandidate' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:resolvedCall type:.Atom visibility:private [final]' type=.Atom origin=null + receiver: GET_VAR ': .KotlinResolutionCandidate declared in .KotlinResolutionCandidate.' type=.KotlinResolutionCandidate origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Atom + CONSTRUCTOR visibility:public <> (candidateDescriptor:.CallableDescriptor) returnType:.Atom [primary] + VALUE_PARAMETER name:candidateDescriptor index:0 type:.CallableDescriptor + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Atom modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:.CallableDescriptor visibility:private [final] + EXPRESSION_BODY + GET_VAR 'candidateDescriptor: .CallableDescriptor declared in .Atom.' type=.CallableDescriptor origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Atom) returnType:.CallableDescriptor + correspondingProperty: PROPERTY name:candidateDescriptor visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Atom + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .CallableDescriptor declared in .Atom' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:candidateDescriptor type:.CallableDescriptor visibility:private [final]' type=.CallableDescriptor origin=null + receiver: GET_VAR ': .Atom declared in .Atom.' type=.Atom origin=null + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [operator] declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[.ResolutionPart] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Owner + CONSTRUCTOR visibility:private <> () returnType:.Owner [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in .ResolutionPart' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Owner modality:FINAL visibility:public superTypes:[.ResolutionPart]' + FUN name:process visibility:public modality:OPEN <> ($this:.Owner, $receiver:.KotlinResolutionCandidate) returnType:kotlin.String + overridden: + public abstract fun process (): kotlin.String declared in .ResolutionPart + $this: VALUE_PARAMETER name: type:.Owner + $receiver: VALUE_PARAMETER name: type:.KotlinResolutionCandidate + BLOCK_BODY + VAR name:candidateDescriptor type:.CallableDescriptor [val] + CALL 'public final fun (): .CallableDescriptor declared in .Atom' type=.CallableDescriptor origin=GET_PROPERTY + $this: CALL 'public final fun (): .Atom declared in .KotlinResolutionCandidate' type=.Atom origin=GET_PROPERTY + $this: GET_VAR ': .KotlinResolutionCandidate declared in .Owner.process' type=.KotlinResolutionCandidate origin=null + WHEN type=kotlin.Unit origin=IF + BRANCH + if: WHEN type=kotlin.Boolean origin=ANDAND + BRANCH + if: TYPE_OP type=kotlin.Boolean origin=INSTANCEOF typeOperand=.MemberDescriptor + GET_VAR 'val candidateDescriptor: .CallableDescriptor [val] declared in .Owner.process' type=.CallableDescriptor origin=null + then: CALL 'public final fun not (): kotlin.Boolean [operator] declared in kotlin.Boolean' type=kotlin.Boolean origin=EXCLEQ + $this: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EXCLEQ + arg0: CALL 'public abstract fun getModality (): @[FlexibleNullability] .Modality? declared in .MemberDescriptor' type=@[FlexibleNullability] .Modality? origin=GET_PROPERTY + $this: TYPE_OP type=.MemberDescriptor origin=IMPLICIT_CAST typeOperand=.MemberDescriptor + GET_VAR 'val candidateDescriptor: .CallableDescriptor [val] declared in .Owner.process' type=.CallableDescriptor origin=null + arg1: CONST Null type=kotlin.Nothing? value=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: CONST Boolean type=kotlin.Boolean value=false + then: BLOCK type=kotlin.Unit origin=null + RETURN type=kotlin.Nothing from='public open fun process (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="OK" + RETURN type=kotlin.Nothing from='public open fun process (): kotlin.String declared in .Owner' + CONST String type=kotlin.String value="FAIL" + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .ResolutionPart + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .ResolutionPart + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .ResolutionPart + $this: VALUE_PARAMETER name: type:kotlin.Any + CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[.Modality] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Final + CONSTRUCTOR visibility:private <> () returnType:.Final [primary] + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS OBJECT name:Final modality:FINAL visibility:public superTypes:[.Modality]' + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in .Modality + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in .Modality + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in .Modality + $this: VALUE_PARAMETER name: type:kotlin.Any diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 5d7d7842cbd..c86e4d91531 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2146,6 +2146,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/firProblems/kt43342.kt"); } + @Test + @TestMetadata("Modality.kt") + public void testModality() throws Exception { + runTest("compiler/testData/ir/irText/firProblems/Modality.kt"); + } + @Test @TestMetadata("MultiList.kt") public void testMultiList() throws Exception {