Skip to content

Commit 2666ba9

Browse files
committed
Describe issue with using compiler plugin in lambdas with DslMarker receivers
1 parent fb38cfd commit 2666ba9

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-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: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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+
Here's the declaration from Compose. Receiver parameter types with annotations similar to this one will conflict with the plugin.
11+
```kotlin
12+
@LayoutScopeMarker
13+
interface ColumnScope
14+
15+
@DslMarker
16+
annotation class LayoutScopeMarker
17+
```
18+
19+
Repro: The snippet below shows a dataframe variable initialized with a local DataFrame type inside a `Column` lambda. `ageComposableLambdaScope` cannot be resolved.
20+
21+
```kotlin
22+
@DataSchema
23+
data class Person(val age: Int, val name: String)
24+
25+
@Composable
26+
fun DataFrameScreen(df: DataFrame<Person>) {
27+
Column {
28+
val filteredDf = remember(df) {
29+
df
30+
.add("ageComposableLambdaScope") { age }
31+
.filter { ageComposableLambdaScope >= 20 }
32+
}
33+
filteredDf.ageComposableLambdaScope // error
34+
}
35+
}
36+
```
37+
38+
Error message:
39+
```
40+
val ColumnsScope<Person_59I>.ageComposableLambdaScope: Int'
41+
cannot be called in this context with an implicit receiver.
42+
Use an explicit receiver if necessary
43+
```
44+
45+
Workaround:
46+
Initialize your dataframe properties outside lambdas with DslMarker receiver parameters.
47+
48+
```kotlin
49+
@DataSchema
50+
data class Person(val age: Int, val name: String)
51+
52+
@Composable
53+
fun DataFrameScreen(df: DataFrame<Person>) {
54+
val filteredDf = remember(df) {
55+
df
56+
.add("ageValidScope") { age }
57+
.filter { ageValidScope >= 20 }
58+
}
59+
filteredDf.ageValidScope // OK
60+
61+
Column {
62+
Text(filteredDf.ageValidScope.toString())
63+
}
64+
}
65+
```

0 commit comments

Comments
 (0)