Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case for polymorphic type parameters in context receivers scope #9

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
FILE fqName:foo.bar fileName:/context_receivers_with_polymorphic_type_parameter.kt
CLASS INTERFACE name:Repository modality:ABSTRACT visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.bar.Repository<T of foo.bar.Repository>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
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:<this> 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:<this> 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:<this> type:kotlin.Any
CLASS CLASS name:IntRepo modality:FINAL visibility:public superTypes:[foo.bar.Repository<kotlin.Int>]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.bar.IntRepo
CONSTRUCTOR visibility:public <> () returnType:foo.bar.IntRepo [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:IntRepo modality:FINAL visibility:public superTypes:[foo.bar.Repository<kotlin.Int>]'
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 foo.bar.Repository
$this: VALUE_PARAMETER name:<this> 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 foo.bar.Repository
$this: VALUE_PARAMETER name:<this> 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 foo.bar.Repository
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FUN name:repo visibility:public modality:FINAL <> () returnType:foo.bar.Repository<kotlin.Int>
annotations:
Provider
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun repo (): foo.bar.Repository<kotlin.Int> declared in foo.bar'
CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in foo.bar.IntRepo' type=foo.bar.IntRepo origin=null
CLASS CLASS name:UseCase modality:FINAL visibility:public superTypes:[kotlin.Any]
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.bar.UseCase<T of foo.bar.UseCase>
TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false
FIELD FIELD_FOR_CLASS_CONTEXT_RECEIVER name:contextReceiverField0 type:foo.bar.Repository<T of foo.bar.UseCase> visibility:private [final]
CONSTRUCTOR visibility:public <> (_context_receiver_0:foo.bar.Repository<T of foo.bar.UseCase>, x:kotlin.Int) returnType:foo.bar.UseCase<T of foo.bar.UseCase> [primary]
VALUE_PARAMETER name:_context_receiver_0 index:0 type:foo.bar.Repository<T of foo.bar.UseCase>
VALUE_PARAMETER name:x index:1 type:kotlin.Int
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
SET_FIELD 'FIELD FIELD_FOR_CLASS_CONTEXT_RECEIVER name:contextReceiverField0 type:foo.bar.Repository<T of foo.bar.UseCase> visibility:private [final]' type=kotlin.Unit origin=null
receiver: GET_VAR '<this>: foo.bar.UseCase<T of foo.bar.UseCase> declared in foo.bar.UseCase' type=foo.bar.UseCase<T of foo.bar.UseCase> origin=null
value: GET_VAR '_context_receiver_0: foo.bar.Repository<T of foo.bar.UseCase> declared in foo.bar.UseCase.<init>' type=foo.bar.Repository<T of foo.bar.UseCase> origin=null
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:UseCase modality:FINAL visibility:public superTypes:[kotlin.Any]'
PROPERTY name:x visibility:public modality:FINAL [val]
FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]
EXPRESSION_BODY
GET_VAR 'x: kotlin.Int declared in foo.bar.UseCase.<init>' type=kotlin.Int origin=INITIALIZE_PROPERTY_FROM_PARAMETER
FUN DEFAULT_PROPERTY_ACCESSOR name:<get-x> visibility:public modality:FINAL <> ($this:foo.bar.UseCase<T of foo.bar.UseCase>) returnType:kotlin.Int
correspondingProperty: PROPERTY name:x visibility:public modality:FINAL [val]
$this: VALUE_PARAMETER name:<this> type:foo.bar.UseCase<T of foo.bar.UseCase>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun <get-x> (): kotlin.Int declared in foo.bar.UseCase'
GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]' type=kotlin.Int origin=null
receiver: GET_VAR '<this>: foo.bar.UseCase<T of foo.bar.UseCase> declared in foo.bar.UseCase.<get-x>' type=foo.bar.UseCase<T of foo.bar.UseCase> 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:<this> 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:<this> 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:<this> type:kotlin.Any
FUN name:f visibility:public modality:FINAL <> () returnType:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in foo.bar'
CALL 'public final fun contextual <T, R> (ev: T of arrow.inject.annotations.RunKt.contextual, f: @[ExtensionFunctionType] kotlin.Function1<T of arrow.inject.annotations.RunKt.contextual, R of arrow.inject.annotations.RunKt.contextual>): R of arrow.inject.annotations.RunKt.contextual [inline] declared in arrow.inject.annotations.RunKt' type=kotlin.Int origin=null
<T>: foo.bar.Repository<kotlin.Int>
<R>: kotlin.Int
ev: CALL 'public final fun repo (): foo.bar.Repository<kotlin.Int> declared in foo.bar' type=foo.bar.Repository<kotlin.Int> origin=null
f: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<foo.bar.Repository<kotlin.Int>, kotlin.Int> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:foo.bar.Repository<kotlin.Int>) returnType:kotlin.Int
$receiver: VALUE_PARAMETER name:$this$contextual type:foo.bar.Repository<kotlin.Int>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f (): kotlin.Int declared in foo.bar'
CALL 'public final fun <get-x> (): kotlin.Int declared in foo.bar.UseCase' type=kotlin.Int origin=GET_PROPERTY
$this: CONSTRUCTOR_CALL 'public constructor <init> (_context_receiver_0: foo.bar.Repository<T of foo.bar.UseCase>, x: kotlin.Int) [primary] declared in foo.bar.UseCase' type=foo.bar.UseCase<kotlin.Int> origin=null
<class: T>: kotlin.Int
_context_receiver_0: GET_VAR '$this$contextual: foo.bar.Repository<kotlin.Int> declared in foo.bar.f.<anonymous>' type=foo.bar.Repository<kotlin.Int> origin=null
x: CONST Int type=kotlin.Int value=0
FUN name:f3 visibility:public modality:FINAL <> () returnType:kotlin.Int
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f3 (): kotlin.Int declared in foo.bar'
CALL 'public final fun contextual <T, R> (ev: T of arrow.inject.annotations.RunKt.contextual, f: @[ExtensionFunctionType] kotlin.Function1<T of arrow.inject.annotations.RunKt.contextual, R of arrow.inject.annotations.RunKt.contextual>): R of arrow.inject.annotations.RunKt.contextual [inline] declared in arrow.inject.annotations.RunKt' type=kotlin.Int origin=null
<T>: foo.bar.Repository<kotlin.Int>
<R>: kotlin.Int
ev: CALL 'public final fun repo (): foo.bar.Repository<kotlin.Int> declared in foo.bar' type=foo.bar.Repository<kotlin.Int> origin=null
f: FUN_EXPR type=@[ExtensionFunctionType] kotlin.Function1<foo.bar.Repository<kotlin.Int>, kotlin.Int> origin=LAMBDA
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> ($receiver:foo.bar.Repository<kotlin.Int>) returnType:kotlin.Int
$receiver: VALUE_PARAMETER name:$this$contextual type:foo.bar.Repository<kotlin.Int>
BLOCK_BODY
RETURN type=kotlin.Nothing from='public final fun f3 (): kotlin.Int declared in foo.bar'
CALL 'public final fun <get-x> (): kotlin.Int declared in foo.bar.UseCase' type=kotlin.Int origin=GET_PROPERTY
$this: CONSTRUCTOR_CALL 'public constructor <init> (_context_receiver_0: foo.bar.Repository<T of foo.bar.UseCase>, x: kotlin.Int) [primary] declared in foo.bar.UseCase' type=foo.bar.UseCase<kotlin.Int> origin=null
<class: T>: kotlin.Int
_context_receiver_0: GET_VAR '$this$contextual: foo.bar.Repository<kotlin.Int> declared in foo.bar.f3.<anonymous>' type=foo.bar.Repository<kotlin.Int> origin=null
x: CONST Int type=kotlin.Int value=0
FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String
BLOCK_BODY
VAR name:result type:kotlin.Int [val]
CALL 'public final fun f (): kotlin.Int declared in foo.bar' type=kotlin.Int origin=null
RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in foo.bar'
WHEN type=kotlin.String 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 'val result: kotlin.Int [val] declared in foo.bar.box' type=kotlin.Int origin=null
arg1: CONST Int type=kotlin.Int value=0
then: CONST String type=kotlin.String value="OK"
BRANCH
if: CONST Boolean type=kotlin.Boolean value=true
then: STRING_CONCATENATION type=kotlin.String
CONST String type=kotlin.String value="Fail: "
GET_VAR 'val result: kotlin.Int [val] declared in foo.bar.box' type=kotlin.Int origin=null
FILE fqName:foo.bar.annotations fileName:/Annotations.kt
CLASS ANNOTATION_CLASS name:Given modality:OPEN visibility:public superTypes:[kotlin.Annotation]
annotations:
Context
Retention(value = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:RUNTIME' type=kotlin.annotation.AnnotationRetention)
Target(allowedTargets = [GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:CLASS' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:FUNCTION' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:PROPERTY' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:VALUE_PARAMETER' type=kotlin.annotation.AnnotationTarget])
MustBeDocumented
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.bar.annotations.Given
CONSTRUCTOR visibility:public <> () returnType:foo.bar.annotations.Given [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Given modality:OPEN visibility:public superTypes:[kotlin.Annotation]'
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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> 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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> 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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
CLASS ANNOTATION_CLASS name:Config modality:OPEN visibility:public superTypes:[kotlin.Annotation]
annotations:
Context
Retention(value = GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:RUNTIME' type=kotlin.annotation.AnnotationRetention)
Target(allowedTargets = [GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:CLASS' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:FUNCTION' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:PROPERTY' type=kotlin.annotation.AnnotationTarget, GET_ENUM 'ENUM_ENTRY IR_EXTERNAL_DECLARATION_STUB name:VALUE_PARAMETER' type=kotlin.annotation.AnnotationTarget])
MustBeDocumented
$this: VALUE_PARAMETER INSTANCE_RECEIVER name:<this> type:foo.bar.annotations.Config
CONSTRUCTOR visibility:public <> () returnType:foo.bar.annotations.Config [primary]
BLOCK_BODY
DELEGATING_CONSTRUCTOR_CALL 'public constructor <init> () [primary] declared in kotlin.Any'
INSTANCE_INITIALIZER_CALL classDescriptor='CLASS ANNOTATION_CLASS name:Config modality:OPEN visibility:public superTypes:[kotlin.Annotation]'
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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> 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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> 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 kotlin.Annotation
$this: VALUE_PARAMETER name:<this> type:kotlin.Any
FILE fqName:foo.bar.identity fileName:/Identity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
FILE: context_receivers_with_polymorphic_type_parameter.kt
package foo.bar

public abstract interface Repository<T> : R|kotlin/Any| {
}
public final class IntRepo : R|foo/bar/Repository<kotlin/Int>| {
public constructor(): R|foo/bar/IntRepo| {
super<R|kotlin/Any|>()
}

}
@R|arrow/inject/annotations/Provider|() public final fun repo(): R|foo/bar/Repository<kotlin/Int>| {
^repo R|foo/bar/IntRepo.IntRepo|()
}
context(R|foo/bar/Repository<T>|)
public final class UseCase<T> : R|kotlin/Any| {
public constructor<T>(x: R|kotlin/Int|): R|foo/bar/UseCase<T>| {
super<R|kotlin/Any|>()
}

public final val x: R|kotlin/Int| = R|<local>/x|
public get(): R|kotlin/Int|

}
public final fun f(): R|kotlin/Int| {
R|arrow/inject/annotations/context|<R|foo/bar/Repository<kotlin/Int>|>()
^f R|foo/bar/UseCase.UseCase|<R|kotlin/Int|>(x = Int(0)).R|SubstitutionOverride<foo/bar/UseCase.x: R|kotlin/Int|>|
}
public final fun f3(): R|kotlin/Int| {
^f3 R|arrow/inject/annotations/contextual|<R|foo/bar/Repository<kotlin/Int>|, R|kotlin/Int|>(R|foo/bar/repo|(), <L> = contextual@fun R|foo/bar/Repository<kotlin/Int>|.<anonymous>(): R|kotlin/Int| <inline=Inline, kind=UNKNOWN> {
^f3 R|foo/bar/UseCase.UseCase|<R|kotlin/Int|>(x = Int(0)).R|SubstitutionOverride<foo/bar/UseCase.x: R|kotlin/Int|>|
}
)
}
public final fun box(): R|kotlin/String| {
lval result: R|kotlin/Int| = R|foo/bar/f|()
^box when () {
==(R|<local>/result|, Int(0)) -> {
String(OK)
}
else -> {
<strcat>(String(Fail: ), R|<local>/result|)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package foo.bar

import arrow.inject.annotations.context
import arrow.inject.annotations.Provider
import arrow.inject.annotations.contextual

interface Repository<T>

class IntRepo : Repository<Int>

@Provider fun repo(): Repository<Int> = IntRepo()

context(Repository<T>)
class UseCase<T>(val x: Int)

fun f(): Int {
context<Repository<Int>>()
return UseCase<Int>(x = 0).x
}

fun f3(): Int {
return contextual<Repository<Int>, Int>(repo()) {
return UseCase<Int>(x = 0).x
}
}

fun box(): String {
val result = f()
return if (result == 0) {
"OK"
} else {
"Fail: $result"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FILE: context_receivers_with_polymorphic_type_parameter.kt
package foo.bar

public abstract fun interface Repository<T> : R|kotlin/Any| {
public abstract fun fetch(): R|T|

}
@R|arrow/inject/annotations/Provider|() public final fun intRepo(): R|foo/bar/Repository<kotlin/Int>| {
^intRepo R|foo/bar/Repository|<R|kotlin/Int|>(<L> = Repository@fun <anonymous>(): R|kotlin/Int| <inline=NoInline> {
^ Int(1)
}
)
}
context(R|foo/bar/Repository<T>|)
public final class UseCase<T> : R|kotlin/Any| {
public constructor<T>(): R|foo/bar/UseCase<T>| {
super<R|kotlin/Any|>()
}

}
public final fun foo(): R|kotlin/Int| {
R|arrow/inject/annotations/context|<R|foo/bar/Repository<kotlin/Int>|>()
^foo R|kotlin/with|<R|foo/bar/UseCase<kotlin/Int>|, R|kotlin/Int|>(R|foo/bar/UseCase.UseCase|<R|kotlin/Int|>(), <L> = with@fun R|foo/bar/UseCase<kotlin/Int>|.<anonymous>(): R|kotlin/Int| <inline=Inline, kind=EXACTLY_ONCE> {
^ this@R|foo/bar/foo|.R|SubstitutionOverride<foo/bar/Repository.fetch: R|kotlin/Int|>|()
}
)
}
public final fun main(): R|kotlin/Unit| {
R|foo/bar/foo|()
}
Loading