ABadHaiku
08/03/2026, 3:59 PMAdam S
08/03/2026, 4:40 PMfun assign(...) or annotation.Adam S
08/03/2026, 4:40 PMABadHaiku
08/03/2026, 4:42 PMAdam S
08/03/2026, 4:43 PMfun assign() an extension function?ABadHaiku
08/03/2026, 4:45 PM@UsesAssignmentOperator
interface IItemAttribute<T> {
context(attrs: IAttributeContainer)
fun assign(value: T)
}
It doesn't work even without the context parameter, though.Adam S
08/03/2026, 4:47 PMABadHaiku
08/03/2026, 4:48 PMAdam S
08/03/2026, 4:50 PMit gives the errordoes the IDE give the error or does it fail when you run
./gradlew assemble?ABadHaiku
08/03/2026, 4:50 PMABadHaiku
08/03/2026, 4:51 PMABadHaiku
08/03/2026, 4:51 PMABadHaiku
08/03/2026, 4:56 PMAdam S
08/04/2026, 6:10 AMYoussef Shoaib [MOD]
08/09/2026, 1:08 AMassign as a deliberate design decisions
The extension point in the compiler doesn't have those restrictions, though. I made my own less-restrictive assign plugin way back as a result. It's very out of date now, so I'm not suggesting you use it, but I'm just saying that it's possible to do what you wantAdam S
08/09/2026, 9:37 AM= inside an init {} block?Youssef Shoaib [MOD]
08/09/2026, 11:55 AMfoo = bar assignments into foo.assign(bar), where illegal means that foo is not a var.
It's been a while, but I think a call like this = bar never gets transformed because the compiler can't make sense of it
Not sure about that runtime error. If I had to guess, it might be because your LHS value wasn't initialized yet? Although I'd expect that the compiler would be able to catch that.Youssef Shoaib [MOD]
08/09/2026, 12:12 PMval. It also require a special annotation on its type. My plugin lifts both restrictions.
Looking into the initialization thing more, it really feels like a bug to me. I have a hypothesis on why it happens (the val that the assign plugin returns to the compiler is already resolved, so normal checks like initialization don't happen).