mirror of
https://github.com/carbon-language/carbon-lang.git
synced 2026-11-16 06:08:10 +00:00
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:
1 parent
e8ffeef7b5
commit
309d3d63c5
9 files changed
+324
-692
No files matched your search
@@ -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));
|
||||
|
||||
Reference in new issue
Block a user