Preventing nested calls with DSL Marker : inconsistent behavior

Hello all,

I would like to prevent inheriting the top scope when using a function with receiver. The DSL marker is made for that but I find its behaviour to be pretty inconsistent.
https://pl.kotl.in/UH894A7DW

Consider the 3 calls in the method run() : ideally all of them should lead to a compilation error because the DSL marker is present on each extension function parameter so nested calls of textFilter() should not be possible.

However, in the first case, the compiler ignores it, in the second it creates a warning and only in the third it leads to a compilation error.

Can someone please explain me this discrepancy ? Are there any workarounds to design a bulletproof DSL builder which prevent using extension functions out of their scope ?

As a side note, I noticed that if I put directly the annotation on the classes (TextContract, Container), then all three calls give me correctly an error. However in my real code, this is not possible because my classes are third party, so I would really like a solution with the annotation on the parameter.

Thanks is advance for any help

Case one doesn’t work because of this problem: https://youtrack.jetbrains.com/issue/KT-23301. Container in the first call is not marked with the annotation, so nothing special is happening.

Case two works correctly, but currently gives only a warning, see https://youtrack.jetbrains.com/issue/KT-23255. It will become an error automatically in version 1.4.

Case three works correctly, as there is no Container implicit receiver there at all.

Thanks for the very thorough answer : it is much clearer now !