Skip to content

Commit 17bcaab

Browse files
committed
Describe issue with using compiler plugin in lambdas with DslMarker receivers
1 parent 0295640 commit 17bcaab

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

docs/StardustDocs/d.tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
<toc-element topic="staticInterpretation.md"/>
5555
<toc-element topic="dataSchema.md"/>
5656
<toc-element topic="compilerPluginExamples.md"/>
57+
<toc-element topic="compilerPluginLimitationsAndWorkarounds.md"/>
5758
</toc-element>
5859
<toc-element topic="operations.md">
5960
<toc-element topic="create.md">
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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

Comments
 (0)