mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-10-02 12:55:48 +01:00
This is closer to [the design](https://github.com/carbon-language/carbon-lang/blob/trunk/docs/design/expressions/indexing.md?plain=1#L55-L64), just lacking `ref`, but does remove a lot of special-casing done for the lookup. The `ErrorInst` changes in `Build*Operator` are to align with what was being done for `IndexWith`; don't do an interface lookup if the relevant operand is an error. Otherwise, that becomes visible because some files have an error operand and don't provide the interface.
75 lines
2.3 KiB
Plaintext
75 lines
2.3 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/full.carbon
|
|
//
|
|
// 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: cannot access member of interface `Core.IndexWith(Core.IntLiteral)` in type `type` that does not implement that interface [MissingImplInMemberAccess]
|
|
// 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 {};
|
|
}
|