We had a discussion with @orangy yesterday about this feature and he expressed some concerns about the feature implementation. Here are some of my thoughts about it. Feel free to add them to the keep.

**Problem:** Basic syntax.

**Solution:** I do not think it is a blocker. I still think that `[A,B].func`

is much more concise. I will use it for further examples.

**Problem:** Functional type syntax.

**Solution:** In proposed above syntax it will look like `[A,B].(C) -> D`

which is concise and does not introduce ambiguities.

**Problem:** Context order. We can have two situations like `with(A){with(B){...}}`

and `with(B){with(A){...}}`

. I think it is a primary problem.

**Solution 1:** Make order matter, which will mean that `[A, B].func`

and `[B, A].func`

are two different functions. I thought about that and it seems like this solution will bring a lot of confusion, so we can reject it for now.

**Solution 2:** Forget about order. Assume that receivers are a set, not list. This means that introducing both `[A, B].func`

and `[B, A].func`

in the same path will rise compile time error. I think we should go for that solution.

**Problem:** Resolution rules. Suppose we have an ordered list of contexts from outer to inner in the function call site like `G, A, B, C`

where `G`

is a global context which corresponds to kotlin file or global function. Global context could be ignored since it does not affect the resolution (in fact, on JVM, global context makes sense since it could correspond to different classloaders). Now we need to establish rules for extension resolution (assuming that order of extensions is ignored)

**Solution:** The obvious solution to make all functions like `[A, B, C]`

, `[A, B]`

, `[B, C]`

and `[A, C]`

available inside `C`

. Order does not matter, so contexts are resolved by type and injected in the function. We need to think about it and see if there are any drawbacks in that.

**Problem:** What contexts could be distinguished by type? Could we assume `A<T1>`

to be different from `A<T2>`

. Need some input on that.

**Problem:** What to do with situation like `G, A, B, A`

with function like `[A,B]`

.

**Solution 1:** Take only last two members of context list. It could create ambiguities.

**Solution 2:** Throw compile time exception in this case and force user to use type aliases to differentiate. In my personal opinion it is better. The situation is rare and ambiguous as it is (you do not know which `this`

you use).

**Problem?:** @orangy mentioned type inference. For now I do not see problem with type inference. For extension functions type is always declared explicitly. Functional types with receivers also require explicit types.

**Problem:** `this`

reference. It requires further discussion. If we assume that several contexts of the same type are not allowed, `this`

could be uniquely reconstructed by type, but there could be some problems with that.

To be continuedâ€¦