CEP-0038: Expected-Type Dyn Conversions¶
Draft
Draft proposal for inferring into_dyn(C) and upcast(C) targets from expected type. V1 requires explicit target contract arguments.
Summary¶
Catalyst should eventually decide whether owned dynamic conversions can infer their target contract from an expected type.
V1 spells destination contracts explicitly for into_dyn(C) and upcast(C).
Example¶
Possible future shape:
fn make_drawable(shape: Circle, allocator: *std.mem.Allocator) Box(dyn Draw) {
return shape.into_dyn(allocator)
}
V1 requires the erased target to remain explicit:
return shape.into_dyn(Draw, allocator)
Motivation¶
Expected-type inference can reduce repetition in return statements, assignments, and argument positions. It can also hide important erased-surface decisions, especially when multiple dyn-safe targets are plausible.
Proposed Direction¶
The proposal should cover:
- expected-type sources that may infer
C; - ambiguity diagnostics;
- interaction with overload resolution and generic parameter inference;
- whether inference applies to borrowed dyn pointer coercions, owned
Boxconversions, or both; - display of inferred erased surfaces in diagnostics.
V1 Compatibility¶
V1 keeps into_dyn(C) and upcast(C) explicit. Boxed dyn upcasts remain explicit consuming operations.