| Thread overview | |||||||||
|---|---|---|---|---|---|---|---|---|---|
|
2 days ago why is this cast required? | ||||
|---|---|---|---|---|
| ||||
![]() |
Without the cast, the error is: > Error: incompatible types for | |||
2 days ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
Dejan Lekic ![]() Posted in reply to DanielG | On Friday, 25 September 2026 at 11:14:50 UTC, DanielG wrote: >
Without the cast, the error is: >Error: incompatible types for Unfortunately you've hit a limitation of how the compiler propagates the expected type into an array literal used as a function argument. You can avoid the cast by explicitly making the first lambda a delegate:
, or by using an explicitly typed variable, which also provides the necessary context:
Why? - Because | |||
2 days ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
DanielG ![]() Posted in reply to Dejan Lekic | I see, thank you! Do you (or anyone else) know the reason for that limitation? Is there some obvious situation where the ambiguity is preferable, versus simply inferring - or trying to infer - the expected type? ie, superficially it seems like the compiler could say, "Hey, they are trying to use this array in the context of a [type X] argument - let's assume that for the moment, and see if it works." Put another way, why is a function argument treated differently than the right side of an explicitly-typed variable assignment? | |||
2 days ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
monkyyy ![]() Posted in reply to DanielG | On Friday, 25 September 2026 at 15:52:04 UTC, DanielG wrote: > Do you (or anyone else) know the reason for that limitation? delegates are twice as big as raw function pointers; when doing airplane surgery it would be irresponsible to add an extra dozenial bytes of ram usage as the airplane may fall out of the sky. Theres a | |||
1 day ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
Dejan Lekic ![]() Posted in reply to DanielG | On Friday, 25 September 2026 at 15:52:04 UTC, DanielG wrote: > I see, thank you! Do you (or anyone else) know the reason for that limitation? Is there some obvious situation where the ambiguity is preferable, versus simply inferring - or trying to infer - the expected type? ie, superficially it seems like the compiler could say, "Hey, they are trying to use this array in the context of a [type X] argument - let's assume that for the moment, and see if it works." Put another way, why is a function argument treated differently than the right side of an explicitly-typed variable assignment? You could answer your own question yourself by thinking why the
workaround works? Think, what is the difference between | |||
1 day ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
DanielG ![]() Posted in reply to Dejan Lekic | I appreciate the reply, but that's not the question I am asking. I am asking why there's a difference between an explicitly typed variable, and an explicitly typed function argument - both of which 'receive' the mixed-type array literal. The compiler will implicitly upgrade the function pointers to delegates in one case, but not the other. What is the basis, or philosophy behind this policy? Why do variable assignments receive this treatment, but not function arguments? IMO this violates the Principle of Least Astonishment.
| |||
23 hours ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
Dejan Lekic ![]() Posted in reply to DanielG | On Saturday, 26 September 2026 at 16:49:48 UTC, DanielG wrote: > I appreciate the reply, but that's not the question I am asking. I am asking why there's a difference between an explicitly typed variable, and an explicitly typed function argument - both of which 'receive' the mixed-type array literal. The compiler will implicitly upgrade the function pointers to delegates in one case, but not the other. What is the basis, or philosophy behind this policy? Why do variable assignments receive this treatment, but not function arguments? IMO this violates the Principle of Least Astonishment. A function argument generally has to be given a type independent of which parameter type it'll end up matching, because overload resolution needs to compare each argument's own type against every candidate's parameter types to pick the best match — if argument inference depended on "the parameter type of whichever overload gets picked," that's circular. A variable declaration ( | |||
21 hours ago Re: why is this cast required? | ||||
|---|---|---|---|---|
| ||||
DanielG ![]() Posted in reply to Dejan Lekic | Ah, I see now! Thank you, that was exactly the information I was looking for. | |||
Permalink
Reply

