Files
carbon-lang/toolchain/check/testdata/impl
Dana Jansens f0e3d04d00 Add a bunch of tests for .Self converting to a FacetValue in specifics inside impl as (#8130)
When `.Self` converts to a FacetValue, we include witnesses for the
interfaces required by the conversion. In the facet type declaration of
an `impl as`, a witness will evaluate to ImplSelfWitness if it's for the
impl'd interface, and to IdentifiedWitness otherwise. Inside a named
constraint, it will evaluates to IdentifiedWitness always. These tests
show that we're failing to resolve these witnesses in the same ways.

For instance, in the
`fail_todo_period_self_converted_in_specific_in_named_constraint.carbon`
test split, we get a failure of inequality:
```
found `C(D as Z & Y)` and `C(D as Z & Y)`
```
These read as the same type and they should be the same constant id, but
they contain different witnesses.

In the named constraint `C(PeriodSelf)` produces this semir when
`PeriodSelf` is replaced by `D` in a specific:
```
%facet_value.4b7: %facet_type = facet_value %D, (%Z.impl_witness, %Y.lookup_impl_witness.7e5) [concrete]
%C.bb4: type = class_type @C, @C(%facet_value.4b7) [concrete]
```
Which is dumped as this in the debugger:
```
  - inst78000182: {kind: ImplWitness, arg0: inst78000180, arg1: specific<none>, type: type(inst(WitnessType))}
  - inst78000186: {kind: LookupImplWitness, arg0: inst78000131, arg1: specific_interface78000000, type: type(inst(WitnessType))}
```

Whereas the facet value constructed directly in the `impl as` facet type
has these witnesses:
```
  - inst78000182: {kind: ImplWitness, arg0: inst78000180, arg1: specific<none>, type: type(inst(WitnessType))}
  - inst78000191: {kind: ImplWitness, arg0: inst78000037, arg1: specific78000027, type: type(inst(WitnessType))}
```

Where the second witness was an IdentifiedWitness(`D as Y`) and it
resolved to the particular impl, as the query is concrete. But in the
first case, it never did because the relationship between `D` and `Z`
was lost (the interface we are impl'ing) so the impl was not found once
the witness became concrete.

We also canonicalize the self from the impl when comparing against
witnesses, which enables one of the new tests to pass
(`period_self_converted_in_specific_in_named_constraint_from_generic_impl.carbon`),
as seen between the first and second commit. But also allows the
`period_self_conversion_in_generic_impl.carbon` test to not crash. This
was the most minimal change toward making all of these tests pass.
2026-11-12 19:14:18 +00:00
..