Use IndirectIndexWith.Ref for subscripting when available (#7975)

When checking `a[i]` for a non-array type, first try
`IndirectIndexWith.Ref`, falling back to `IndexWith.At`, per the
indexing design. This allows subscripting to produce a reference
expression, so that `a[i] = v` works and non-copyable elements can be
accessed.

Extracted from #7536 (the `Core.Slice` proposal).
This commit is contained in:
David Blaikie authored and GitHub committed 2026-10-17 00:14:10 +00:00
1 parent e8ffeef7b5
commit 309d3d63c5
9 files changed
+324 -692

No files matched your search

+6
View File
@@ -200,6 +200,12 @@ static auto GetClangOperatorKind(Context& context, SemIR::LocId loc_id,
return clang::OO_Subscript;
}
// C++ `operator[]` is found through `IndexWith`, which subscripting falls
// back to.
case CoreIdentifier::IndirectIndexWith: {
return std::nullopt;
}
default: {
context.TODO(loc_id, llvm::formatv("Unsupported operator interface `{0}`",
interface_name));