From a3fa2dc9bf3a38bde6b4ee45c70730ac46580ed7 Mon Sep 17 00:00:00 2001 From: "Anastasia.Shadrina" Date: Thu, 31 Mar 2022 15:06:35 +0700 Subject: [PATCH] [Tests] Fix contextualInlineCall.kt to avoid subtyping relation error --- .../contextReceivers/contextualInlineCall.kt | 8 ++- .../contextualInlineCall.fir.ir.txt | 59 +++++++++++++++---- .../contextualInlineCall.fir.kt.txt | 20 ++++++- .../contextualInlineCall.ir.txt | 59 +++++++++++++++---- .../contextReceivers/contextualInlineCall.kt | 10 ++-- .../contextualInlineCall.kt.txt | 19 +++++- 6 files changed, 136 insertions(+), 39 deletions(-) diff --git a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextualInlineCall.kt b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextualInlineCall.kt index dee42d8903e..e974977a0ee 100644 --- a/compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextualInlineCall.kt +++ b/compiler/testData/codegen/box/extensionFunctions/contextReceivers/contextualInlineCall.kt @@ -18,9 +18,11 @@ inline fun Int.testInlineWithExtensionAndArg(i: Int) = this@Int + i + c() context(Context) inline fun Int.testInlineWithExtensionAndMultipleArgs(i1: Int, i2: Int) = this@Int + i1 + i2 + c() -context(Context, Any) +class A(val a: Any?) + +context(Context, A) inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(i1: Int = 1, i2: Int = 2) = - this@Int + i1 + i2 + c() + if (this@Any == null) 0 else 1 + this@Int + i1 + i2 + c() + if (this@A.a == null) 0 else 1 fun box(): String = with(Context()) { var result = 0 @@ -28,7 +30,7 @@ fun box(): String = with(Context()) { result += testInlineWithArg(1) result += 1.testInlineWithExtensionAndArg(1) result += 1.testInlineWithExtensionAndMultipleArgs(1, 2) - with(1) { + with(A(1)) { result += 1.testInlineWithExtensionAndMultipleContextsAndArgs(1, 2) result += 1.testInlineWithExtensionAndMultipleContextsAndArgs() } diff --git a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.ir.txt b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.ir.txt index c813ba1d380..b25fe1d65a4 100644 --- a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.ir.txt +++ b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.ir.txt @@ -69,11 +69,42 @@ FILE fqName: fileName:/contextualInlineCall.kt other: GET_VAR 'i2: kotlin.Int declared in .testInlineWithExtensionAndMultipleArgs' type=kotlin.Int origin=null other: CALL 'public final fun c (): kotlin.Int declared in .Context' type=kotlin.Int origin=null $this: GET_VAR '_context_receiver_0: .Context declared in .testInlineWithExtensionAndMultipleArgs' type=.Context origin=null - FUN name:testInlineWithExtensionAndMultipleContextsAndArgs visibility:public modality:FINAL <> ($receiver:kotlin.Int, _context_receiver_0:.Context, _context_receiver_1:kotlin.Any, i1:kotlin.Int, i2:kotlin.Int) returnType:kotlin.Int [inline] + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> (a:kotlin.Any?) returnType:.A [primary] + VALUE_PARAMETER name:a index:0 type:kotlin.Any? + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Any? visibility:private [final] + EXPRESSION_BODY + GET_VAR 'a: kotlin.Any? declared in .A.' type=kotlin.Any? origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Any? + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Any? declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Any? visibility:private [final]' type=kotlin.Any? origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A 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 + FUN name:testInlineWithExtensionAndMultipleContextsAndArgs visibility:public modality:FINAL <> ($receiver:kotlin.Int, _context_receiver_0:.Context, _context_receiver_1:.A, i1:kotlin.Int, i2:kotlin.Int) returnType:kotlin.Int [inline] contextReceiverParametersCount: 2 $receiver: VALUE_PARAMETER name: type:kotlin.Int VALUE_PARAMETER name:_context_receiver_0 index:0 type:.Context - VALUE_PARAMETER name:_context_receiver_1 index:1 type:kotlin.Any + VALUE_PARAMETER name:_context_receiver_1 index:1 type:.A VALUE_PARAMETER name:i1 index:2 type:kotlin.Int EXPRESSION_BODY CONST Int type=kotlin.Int value=1 @@ -81,7 +112,7 @@ FILE fqName: fileName:/contextualInlineCall.kt EXPRESSION_BODY CONST Int type=kotlin.Int value=2 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' + RETURN type=kotlin.Nothing from='public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS @@ -94,7 +125,8 @@ FILE fqName: fileName:/contextualInlineCall.kt other: WHEN type=kotlin.Int origin=IF BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR '_context_receiver_1: kotlin.Any declared in .testInlineWithExtensionAndMultipleContextsAndArgs' type=kotlin.Any origin=null + arg0: CALL 'public final fun (): kotlin.Any? declared in .A' type=kotlin.Any? origin=GET_PROPERTY + $this: GET_VAR '_context_receiver_1: .A declared in .testInlineWithExtensionAndMultipleContextsAndArgs' type=.A origin=null arg1: CONST Null type=kotlin.Nothing? value=null then: CONST Int type=kotlin.Int value=0 BRANCH @@ -140,29 +172,30 @@ FILE fqName: fileName:/contextualInlineCall.kt i1: CONST Int type=kotlin.Int value=1 i2: CONST Int type=kotlin.Int value=2 CALL 'public final fun with (receiver: T of kotlin.StandardKt.with, block: @[ExtensionFunctionType] kotlin.Function1): R of kotlin.StandardKt.with [inline] declared in kotlin.StandardKt' type=kotlin.Unit origin=null - : kotlin.Int + : .A : kotlin.Unit - receiver: CONST Int type=kotlin.Int value=1 - block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Int) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name:$this$with type:kotlin.Int + receiver: CONSTRUCTOR_CALL 'public constructor (a: kotlin.Any?) [primary] declared in .A' type=.A origin=null + a: CONST Int type=kotlin.Int value=1 + block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<.A, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.A) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$with type:.A BLOCK_BODY SET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Unit origin=PLUSEQ CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Int origin=null - other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null + other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null $receiver: CONST Int type=kotlin.Int value=1 _context_receiver_0: GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null - _context_receiver_1: GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null + _context_receiver_1: GET_VAR '$this$with: .A declared in .box..' type=.A origin=null i1: CONST Int type=kotlin.Int value=1 i2: CONST Int type=kotlin.Int value=2 SET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Unit origin=PLUSEQ CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=null $this: GET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Int origin=null - other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null + other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (_context_receiver_0: .Context, _context_receiver_1: .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null $receiver: CONST Int type=kotlin.Int value=1 _context_receiver_0: GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null - _context_receiver_1: GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null + _context_receiver_1: GET_VAR '$this$with: .A declared in .box..' type=.A origin=null RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' WHEN type=kotlin.String origin=IF BRANCH diff --git a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.kt.txt b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.kt.txt index eb8af7a6d1a..0bdc80df848 100644 --- a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.kt.txt +++ b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.fir.kt.txt @@ -27,9 +27,22 @@ inline fun Int.testInlineWithExtensionAndMultipleArgs(_context_receiver_0: Conte return .plus(other = i1).plus(other = i2).plus(other = _context_receiver_0.c()) } -inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(_context_receiver_0: Context, _context_receiver_1: Any, i1: Int = 1, i2: Int = 2): Int { +class A { + constructor(a: Any?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: Any? + field = a + get + +} + +inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(_context_receiver_0: Context, _context_receiver_1: A, i1: Int = 1, i2: Int = 2): Int { return .plus(other = i1).plus(other = i2).plus(other = _context_receiver_0.c()).plus(other = when { - EQEQ(arg0 = _context_receiver_1, arg1 = null) -> 0 + EQEQ(arg0 = _context_receiver_1.(), arg1 = null) -> 0 else -> 1 }) } @@ -41,7 +54,7 @@ fun box(): String { result = result.plus(other = testInlineWithArg(_context_receiver_0 = $this$with, i = 1)) result = result.plus(other = 1.testInlineWithExtensionAndArg(_context_receiver_0 = $this$with, i = 1)) result = result.plus(other = 1.testInlineWithExtensionAndMultipleArgs(_context_receiver_0 = $this$with, i1 = 1, i2 = 2)) - with(receiver = 1, block = local fun Int.() { + with(receiver = A(a = 1), block = local fun A.() { result = result.plus(other = 1.testInlineWithExtensionAndMultipleContextsAndArgs(_context_receiver_0 = $this$with, _context_receiver_1 = $this$with, i1 = 1, i2 = 2)) result = result.plus(other = 1.testInlineWithExtensionAndMultipleContextsAndArgs(_context_receiver_0 = $this$with, _context_receiver_1 = $this$with)) } @@ -53,3 +66,4 @@ fun box(): String { } ) } + diff --git a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.ir.txt b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.ir.txt index dd7d11bfb10..dd4610b2110 100644 --- a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.ir.txt +++ b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.ir.txt @@ -69,11 +69,42 @@ FILE fqName: fileName:/contextualInlineCall.kt other: GET_VAR 'i2: kotlin.Int declared in .testInlineWithExtensionAndMultipleArgs' type=kotlin.Int origin=null other: CALL 'public final fun c (): kotlin.Int declared in .Context' type=kotlin.Int origin=null $this: GET_VAR ': .Context declared in .testInlineWithExtensionAndMultipleArgs' type=.Context origin=null - FUN name:testInlineWithExtensionAndMultipleContextsAndArgs visibility:public modality:FINAL <> ($receiver:kotlin.Int, :.Context, :kotlin.Any, i1:kotlin.Int, i2:kotlin.Int) returnType:kotlin.Int [inline] + CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.A + CONSTRUCTOR visibility:public <> (a:kotlin.Any?) returnType:.A [primary] + VALUE_PARAMETER name:a index:0 type:kotlin.Any? + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () [primary] declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:a visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Any? visibility:private [final] + EXPRESSION_BODY + GET_VAR 'a: kotlin.Any? declared in .A.' type=kotlin.Any? origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.A) returnType:kotlin.Any? + correspondingProperty: PROPERTY name:a visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.A + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): kotlin.Any? declared in .A' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:a type:kotlin.Any? visibility:private [final]' type=kotlin.Any? origin=null + receiver: GET_VAR ': .A declared in .A.' type=.A 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 + FUN name:testInlineWithExtensionAndMultipleContextsAndArgs visibility:public modality:FINAL <> ($receiver:kotlin.Int, :.Context, :.A, i1:kotlin.Int, i2:kotlin.Int) returnType:kotlin.Int [inline] contextReceiverParametersCount: 2 $receiver: VALUE_PARAMETER name: type:kotlin.Int VALUE_PARAMETER name: index:0 type:.Context - VALUE_PARAMETER name: index:1 type:kotlin.Any + VALUE_PARAMETER name: index:1 type:.A VALUE_PARAMETER name:i1 index:2 type:kotlin.Int EXPRESSION_BODY CONST Int type=kotlin.Int value=1 @@ -81,7 +112,7 @@ FILE fqName: fileName:/contextualInlineCall.kt EXPRESSION_BODY CONST Int type=kotlin.Int value=2 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' + RETURN type=kotlin.Nothing from='public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS $this: CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUS @@ -94,7 +125,8 @@ FILE fqName: fileName:/contextualInlineCall.kt other: WHEN type=kotlin.Int origin=IF BRANCH if: CALL 'public final fun EQEQ (arg0: kotlin.Any?, arg1: kotlin.Any?): kotlin.Boolean declared in kotlin.internal.ir' type=kotlin.Boolean origin=EQEQ - arg0: GET_VAR ': kotlin.Any declared in .testInlineWithExtensionAndMultipleContextsAndArgs' type=kotlin.Any origin=null + arg0: CALL 'public final fun (): kotlin.Any? declared in .A' type=kotlin.Any? origin=GET_PROPERTY + $this: GET_VAR ': .A declared in .testInlineWithExtensionAndMultipleContextsAndArgs' type=.A origin=null arg1: CONST Null type=kotlin.Nothing? value=null then: CONST Int type=kotlin.Int value=0 BRANCH @@ -140,29 +172,30 @@ FILE fqName: fileName:/contextualInlineCall.kt i1: CONST Int type=kotlin.Int value=1 i2: CONST Int type=kotlin.Int value=2 CALL 'public final fun with (receiver: T of kotlin.StandardKt.with, block: @[ExtensionFunctionType] kotlin.Function1): R of kotlin.StandardKt.with [inline] declared in kotlin.StandardKt' type=kotlin.Unit origin=null - : kotlin.Int + : .A : kotlin.Unit - receiver: CONST Int type=kotlin.Int value=1 - block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1 origin=LAMBDA - FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Int) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name:$this$with type:kotlin.Int + receiver: CONSTRUCTOR_CALL 'public constructor (a: kotlin.Any?) [primary] declared in .A' type=.A origin=null + a: CONST Int type=kotlin.Int value=1 + block: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<.A, kotlin.Unit> origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.A) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name:$this$with type:.A BLOCK_BODY SET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Unit origin=PLUSEQ CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ $this: GET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Int origin=PLUSEQ - other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null + other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null $receiver: CONST Int type=kotlin.Int value=1 : GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null - : GET_VAR '$this$with: kotlin.Int declared in .box..' type=kotlin.Int origin=null + : GET_VAR '$this$with: .A declared in .box..' type=.A origin=null i1: CONST Int type=kotlin.Int value=1 i2: CONST Int type=kotlin.Int value=2 SET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Unit origin=PLUSEQ CALL 'public final fun plus (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=PLUSEQ $this: GET_VAR 'var result: kotlin.Int [var] declared in .box.' type=kotlin.Int origin=PLUSEQ - other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : kotlin.Any, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null + other: CALL 'public final fun testInlineWithExtensionAndMultipleContextsAndArgs (: .Context, : .A, i1: kotlin.Int, i2: kotlin.Int): kotlin.Int [inline] declared in ' type=kotlin.Int origin=null $receiver: CONST Int type=kotlin.Int value=1 : GET_VAR '$this$with: .Context declared in .box.' type=.Context origin=null - : GET_VAR '$this$with: kotlin.Int declared in .box..' type=kotlin.Int origin=null + : GET_VAR '$this$with: .A declared in .box..' type=.A origin=null RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' WHEN type=kotlin.String origin=IF BRANCH diff --git a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt index 32887fc278d..280e426f67b 100644 --- a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt +++ b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt @@ -17,9 +17,11 @@ inline fun Int.testInlineWithExtensionAndArg(i: Int) = this@Int + i + c() context(Context) inline fun Int.testInlineWithExtensionAndMultipleArgs(i1: Int, i2: Int) = this@Int + i1 + i2 + c() -context(Context, Any) +class A(val a: Any?) + +context(Context, A) inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(i1: Int = 1, i2: Int = 2) = - this@Int + i1 + i2 + c() + if (this@Any == null) 0 else 1 + this@Int + i1 + i2 + c() + if (this@A.a == null) 0 else 1 fun box(): String = with(Context()) { var result = 0 @@ -27,9 +29,9 @@ fun box(): String = with(Context()) { result += testInlineWithArg(1) result += 1.testInlineWithExtensionAndArg(1) result += 1.testInlineWithExtensionAndMultipleArgs(1, 2) - with(1) { + with(A(1)) { result += 1.testInlineWithExtensionAndMultipleContextsAndArgs(1, 2) result += 1.testInlineWithExtensionAndMultipleContextsAndArgs() } return if (result == 23) "OK" else "fail" -} +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt.txt b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt.txt index df623e8b9b8..eb213ca462b 100644 --- a/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt.txt +++ b/compiler/testData/ir/irText/declarations/contextReceivers/contextualInlineCall.kt.txt @@ -27,9 +27,22 @@ inline fun Int.testInlineWithExtensionAndMultipleArgs(: Context, i1: Int, return .plus(other = i1).plus(other = i2).plus(other = .c()) } -inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(: Context, : Any, i1: Int = 1, i2: Int = 2): Int { +class A { + constructor(a: Any?) /* primary */ { + super/*Any*/() + /* () */ + + } + + val a: Any? + field = a + get + +} + +inline fun Int.testInlineWithExtensionAndMultipleContextsAndArgs(: Context, : A, i1: Int = 1, i2: Int = 2): Int { return .plus(other = i1).plus(other = i2).plus(other = .c()).plus(other = when { - EQEQ(arg0 = , arg1 = null) -> 0 + EQEQ(arg0 = .(), arg1 = null) -> 0 else -> 1 }) } @@ -41,7 +54,7 @@ fun box(): String { result = result.plus(other = testInlineWithArg( = $this$with, i = 1)) result = result.plus(other = 1.testInlineWithExtensionAndArg( = $this$with, i = 1)) result = result.plus(other = 1.testInlineWithExtensionAndMultipleArgs( = $this$with, i1 = 1, i2 = 2)) - with(receiver = 1, block = local fun Int.() { + with(receiver = A(a = 1), block = local fun A.() { result = result.plus(other = 1.testInlineWithExtensionAndMultipleContextsAndArgs( = $this$with, = $this$with, i1 = 1, i2 = 2)) result = result.plus(other = 1.testInlineWithExtensionAndMultipleContextsAndArgs( = $this$with, = $this$with)) }