Files
carbon-lang/toolchain/check/testdata/impl/period_self.carbon
T
Dana Jansens e41862d55f Handle ImplSelfWitness appearing in the RHS of a rewrite constraint in impl decl (#7943)
Normally ImplSelfWitness would be replaced in an impl decl by the time
we are constructing the witness table. If it was part of an access to an
associated constant, rewrite constraint resolution would have replaced
that access with the value assigned to the associated constant already.
But we can use `.Self` in places where it converts and forms a
FacetValue, which preserves the ImplSelfWitness in the witness block of
the FacetValue. In that case, we want to replace it with the impl's
ImplWitness before we put it into the witness table.

This is a followup fix for
https://github.com/carbon-language/carbon-lang/pull/7930 which
introduces the CARBON_FATAL incorrectly, now that we know how to run
into it.

Add some tests that cover these situations, including one that tries to
access using the FacetValue and its witness, which fails, as a TODO
test.
2026-10-14 17:54:41 +00:00

32 lines
1.1 KiB
Plaintext

// Part of the Carbon Language project, under the Apache License v2.0 with LLVM
// Exceptions. See /LICENSE for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
// INCLUDE-FILE: toolchain/testing/testdata/min_prelude/convert.carbon
//
// AUTOUPDATE
// TIP: To test this file alone, run:
// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/impl/period_self.carbon
// TIP: To dump output, run:
// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/impl/period_self.carbon
// --- period_self_converted_in_impl_as_decl.carbon
library "[[@TEST_NAME]]";
interface Z {
let Z1: type;
}
interface Y {}
impl forall [T: Z] T as Y {}
class C(T: Z & Y) {}
class D;
// This forms the specific `C(.Self)` where `.Self` is of type `Z`
// but we need type `Z & Y` so a conversion takes place. This forms
// a FacetValue with two witnesses. The witness for `Y` is symbolic
// (due to .Self) and points to the impl above. But the witness for
// `Z` is not symbolic and points to the impl being declared here.
impl D as Z where .Z1 = C(.Self) {}