Is it well known that with two function receivers ...
# compose
a
Is it well known that with two function receivers with the same extended methods on
Modifier
your code won't compile? See 🧵.
Copy code
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:
Copy code
'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
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
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
It is a bit confusing. Would you mind filing an issue in the Compose tracker linked in the channel topic?
a
Sure. About the error message?
z
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
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
I think the error message would make more sense if the modifier functions in both scopes didn’t have the same name.