|
| 1 | +# Known limitations and workarounds |
| 2 | + |
| 3 | +### Compiler plugin in lambdas with receiver marked as DslMarker |
| 4 | + |
| 5 | +Problem: Property calls on a dataframe type created inside @Composable `Column { }` lambda cannot be resolved. |
| 6 | +[Issue 1604](https://github.com/Kotlin/dataframe/issues/1604) |
| 7 | + |
| 8 | +The lambda of `Column` has a receiver parameter `content: @Composable ColumnScope.() -> Unit`. |
| 9 | + |
| 10 | +```kotlin |
| 11 | +@LayoutScopeMarker |
| 12 | +interface ColumnScope |
| 13 | + |
| 14 | +@DslMarker |
| 15 | +annotation class LayoutScopeMarker |
| 16 | +``` |
| 17 | + |
| 18 | +Repro: The snippet below shows a dataframe variable initialized with a local DataFrame type inside a `Column` lambda. `ageComposableLambdaScope` cannot be resolved. |
| 19 | + |
| 20 | +```kotlin |
| 21 | +@DataSchema |
| 22 | +data class Person(val age: Int, val name: String) |
| 23 | + |
| 24 | +@Composable |
| 25 | +fun DataFrameScreen(df: DataFrame<Person>) { |
| 26 | + Column { |
| 27 | + val filteredDf = remember(df) { |
| 28 | + df |
| 29 | + .add("ageComposableLambdaScope") { age } |
| 30 | + .filter { ageComposableLambdaScope >= 20 } |
| 31 | + } |
| 32 | + filteredDf.ageComposableLambdaScope // error |
| 33 | + } |
| 34 | +} |
| 35 | +``` |
| 36 | + |
| 37 | +Error message: |
| 38 | +``` |
| 39 | +val ColumnsScope<Person_59I>.ageComposableLambdaScope: Int' |
| 40 | +cannot be called in this context with an implicit receiver. |
| 41 | +Use an explicit receiver if necessary |
| 42 | +``` |
| 43 | + |
| 44 | +Workaround: |
| 45 | +Initialize your dataframe properties outside lambdas with DslMarker receiver parameters. |
| 46 | + |
| 47 | +```kotlin |
| 48 | +@DataSchema |
| 49 | +data class Person(val age: Int, val name: String) |
| 50 | + |
| 51 | +@Composable |
| 52 | +fun DataFrameScreen(df: DataFrame<Person>) { |
| 53 | + val filteredDf = remember(df) { |
| 54 | + df |
| 55 | + .add("ageValidScope") { age } |
| 56 | + .filter { ageValidScope >= 20 } |
| 57 | + } |
| 58 | + filteredDf.ageValidScope // OK |
| 59 | + |
| 60 | + Column { |
| 61 | + Text(filteredDf.ageValidScope.toString()) |
| 62 | + } |
| 63 | +} |
| 64 | +``` |
0 commit comments