From b91ad3be367a37aec30f41333fd8e6d79cc2e3c8 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 24 Jun 2025 13:37:55 -0400 Subject: [PATCH] Add tests for accessing an aggregate member constant through an ImplWitnessAccess (#5702) --- .../facet/aggregate_through_access.carbon | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 toolchain/check/testdata/facet/aggregate_through_access.carbon diff --git a/toolchain/check/testdata/facet/aggregate_through_access.carbon b/toolchain/check/testdata/facet/aggregate_through_access.carbon new file mode 100644 index 000000000000..cc6a305f2201 --- /dev/null +++ b/toolchain/check/testdata/facet/aggregate_through_access.carbon @@ -0,0 +1,72 @@ +// 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 +// +// AUTOUPDATE +// TIP: To test this file alone, run: +// TIP: bazel test //toolchain/testing:file_test --test_arg=--file_tests=toolchain/check/testdata/facet/aggregate_through_access.carbon +// TIP: To dump output, run: +// TIP: bazel run //toolchain/testing:file_test -- --dump_output --file_tests=toolchain/check/testdata/facet/aggregate_through_access.carbon + +// --- fail_todo_tuple_access_through_witness.carbon +library "[[@TEST_NAME]]"; + +interface Z { + let X:! type; +} + +// CHECK:STDERR: fail_todo_tuple_access_through_witness.carbon:[[@LINE+4]]:34: error: type `type` does not support tuple indexing; only tuples can be indexed that way [TupleIndexOnANonTupleType] +// CHECK:STDERR: fn F(T:! Z where .X = ({}, )) -> T.X.0 { +// CHECK:STDERR: ^~~~~ +// CHECK:STDERR: +fn F(T:! Z where .X = ({}, )) -> T.X.0 { + return {}; +} + +// --- fail_todo_struct_access_through_witness.carbon +library "[[@TEST_NAME]]"; + +interface Z { + let X:! type; +} + +// CHECK:STDERR: fail_todo_struct_access_through_witness.carbon:[[@LINE+4]]:36: error: type `type` does not support qualified expressions [QualifiedExprUnsupported] +// CHECK:STDERR: fn F(T:! Z where .X = {.t: ()}) -> T.X.t { +// CHECK:STDERR: ^~~~~ +// CHECK:STDERR: +fn F(T:! Z where .X = {.t: ()}) -> T.X.t { + return (); +} + +// --- fail_todo_array_access_through_witness.carbon +library "[[@TEST_NAME]]"; + +interface Z { + let X:! type; +} + +// CHECK:STDERR: fail_todo_array_access_through_witness.carbon:[[@LINE+4]]:40: error: type `type` does not support indexing [TypeNotIndexable] +// CHECK:STDERR: fn F(T:! Z where .X = array({}, 1)) -> T.X[0] { +// CHECK:STDERR: ^~~~~~ +// CHECK:STDERR: +fn F(T:! Z where .X = array({}, 1)) -> T.X[0] { + return {}; +} + +// --- impl_access_through_witness.carbon +library "[[@TEST_NAME]]"; + +interface Z { + let X1:! type; +} + +interface Y { + let X2:! type; +} + +class C; +impl C as Y where .X2 = {} {} + +fn F(T:! Z where .X1 = C) -> T.X1.(Y.X2) { + return {}; +}