16412, “vasslitvinov”, “CG: implicit coercion”, “2020-09-18T01:25:53Z”
Main issue: #8629
How does CG (constrained generics) design support coercions?
Consider three types
C, such that there is an implicit coercion from
B and from
C. In my code:
The interface requires
proc foo(x: B).
Within the CG function, I call
arghas the type
The interface is implemented with
proc foo(x: C).
Should this be allowed? This sounds natural.
Cons: we currently do not allow transitive implicit coercion. If an implicit coercion from
C is not defined, it is invalid to invoke
proc foo(x:C) on
arg:A. The above scenario would bypass this restriction.
One solution could be to allow only one coercion for any given argument. In the above scenario, either the call within the CG function would have to cast expicitly
arg:B or the interface would have to be implemented with
proc foo(x:B), not both.