Skip to content

ImplicitAs does not know about builtin conversions #5750

Open
@danakj

Description

@danakj

Description of the bug:

  • Tuples of X can convert to tuples of Y if X to Y is a builtin conversion
  • Structs of different field orders but same field types can convert
  • Facet types can convert to other facet types if the former satisfies the later's requirements

ImplicitAs is not implemented for any of these. For example with facet types: https://carbon.godbolt.org/z/o1fK9s8cr

fn Convert(T:! type, U:! ImplicitAs(T)) {}

interface I { let X:! type; }

fn F() {
    Convert(I, I where .X = ());
}
<source>:11:5: error: cannot convert type `I where .(I.X) = ()` into type implementing `ImplicitAs(I)`
    Convert(I, I where .X = ());
    ^~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>:6:1: note: while deducing parameters of generic declared here
fn Convert(T:! type, U:! ImplicitAs(T)) {}
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@josh11b suggested maybe we need to write an impl with builtin conditions, something like:

impl forall [T:! <builtin>, U:! <builtin(where U can convert to T)>] T as ImplicitAs(U) {
  fn Convert[self: Self]() = “builtin”;
}

What did you do, or what's a simple way to reproduce the bug?

No response

What did you expect to happen?

No response

What actually happened?

No response

Any other information, logs, or outputs that you want to share?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions