https://kotlinlang.org logo
Title
a

adjpd

09/13/2021, 8:41 PM
Is it well known that with two function receivers with the same extended methods on
Modifier
your code won't compile? See 🧵.
Column {
  Box {
    Text("hi", Modifier.align(Alignment.End))
  }
}
This won't compile because both
Column
and
Box
have the same modifier
Modifier.align
The compiler cryptically tells you:
'fun Modifier.align(alignment: Alignment.Horizontal): Modifier' can't be called in this context by implicit receiver. Use the explicit one if necessary
I think it's this issue. But the issue was filed nearly three years ago.
z

Zach Klippenstein (he/him) [MOD]

09/13/2021, 9:15 PM
Alignment.End
is an
Alignment.Horizontal
, not an
Alignment
. Those two interfaces are not actually related by subtyping.
BoxScope.align
takes the latter, so I think you need to pass something like
TopEnd
,
CenterEnd
, or `BottomEnd`: https://developer.android.com/reference/kotlin/androidx/compose/ui/Alignment.Companion
🙌 1
a

adjpd

09/13/2021, 9:27 PM
Yes, you're right. Thanks That is an horrific error message, however. And the different types of
Alignment
is different locations is rather perplexing.
z

Zach Klippenstein (he/him) [MOD]

09/13/2021, 9:50 PM
It is a bit confusing. Would you mind filing an issue in the Compose tracker linked in the channel topic?
a

adjpd

09/14/2021, 9:37 AM
Sure. About the error message?
z

Zach Klippenstein (he/him) [MOD]

09/14/2021, 2:21 PM
Yea. I’m not sure if there’s anything that can be done to improve it at this point but maybe a lint check or something given how easy it is to miss that the alignment types are actually unrelated
a

adjpd

09/14/2021, 2:58 PM
There seems to be two issues. The first is confusing naming of Alignment etc. The second is the error message. If the former would be clearer then the latter wouldn't happen. But yeah, a lint check or something may give some extra help. Thanks for the suggestion.
z

Zach Klippenstein (he/him) [MOD]

09/14/2021, 3:05 PM
I think the error message would make more sense if the modifier functions in both scopes didn’t have the same name.