From a3d52b089d01e245b6e4aaf836465d39627012f4 Mon Sep 17 00:00:00 2001 From: Jon Ross-Perkins Date: Mon, 24 Jul 2023 15:31:39 -0700 Subject: [PATCH] Fix missing assignment to me_value found by msan. (#3019) Looks like a small oversight in #2946. Probably missed because type access shouldn't really access the me_value. --- explorer/ast/value.cpp | 10 +++++----- explorer/ast/value.h | 2 +- explorer/interpreter/interpreter.cpp | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/explorer/ast/value.cpp b/explorer/ast/value.cpp index 38f53a6275d3..08ab579c1dd4 100644 --- a/explorer/ast/value.cpp +++ b/explorer/ast/value.cpp @@ -173,7 +173,7 @@ static auto GetPositionalElement(Nonnull tuple, static auto GetNamedElement(Nonnull arena, Nonnull v, const ElementPath::Component& field, SourceLocation source_loc, - Nonnull me_value) + std::optional> me_value) -> ErrorOr> { CARBON_CHECK(field.element()->kind() == ElementKind::NamedElement) << "Invalid element, expecting NamedElement"; @@ -199,7 +199,7 @@ static auto GetNamedElement(Nonnull arena, Nonnull v, mem_decl.has_value()) { const auto& fun_decl = cast(**mem_decl); if (fun_decl.is_method()) { - return arena->New(&fun_decl, me_value, + return arena->New(&fun_decl, *me_value, &impl_witness->bindings()); } else { // Class function. @@ -243,7 +243,7 @@ static auto GetNamedElement(Nonnull arena, Nonnull v, // Found a method. Turn it into a bound method. const auto& m = cast(**func); if (m.declaration().virt_override() == VirtualOverride::None) { - return arena->New(&m.declaration(), me_value, + return arena->New(&m.declaration(), *me_value, &class_type.bindings()); } // Method is virtual, get child-most class value and perform vtable @@ -306,7 +306,7 @@ static auto GetNamedElement(Nonnull arena, Nonnull v, static auto GetElement(Nonnull arena, Nonnull v, const ElementPath::Component& path_comp, SourceLocation source_loc, - Nonnull me_value) + std::optional> me_value) -> ErrorOr> { switch (path_comp.element()->kind()) { case ElementKind::NamedElement: @@ -335,7 +335,7 @@ static auto GetElement(Nonnull arena, Nonnull v, auto Value::GetElement(Nonnull arena, const ElementPath& path, SourceLocation source_loc, - Nonnull me_value) const + std::optional> me_value) const -> ErrorOr> { Nonnull value(this); for (const ElementPath::Component& field : path.components_) { diff --git a/explorer/ast/value.h b/explorer/ast/value.h index c3c23f61b930..6ec59bdfc937 100644 --- a/explorer/ast/value.h +++ b/explorer/ast/value.h @@ -73,7 +73,7 @@ class Value { // `me_value`, otherwise pass `*this`. auto GetElement(Nonnull arena, const ElementPath& path, SourceLocation source_loc, - Nonnull me_value) const + std::optional> me_value) const -> ErrorOr>; // Returns a copy of *this, but with the sub-Value specified by `path` diff --git a/explorer/interpreter/interpreter.cpp b/explorer/interpreter/interpreter.cpp index 8ddb82ee7bf0..52eec8114663 100644 --- a/explorer/interpreter/interpreter.cpp +++ b/explorer/interpreter/interpreter.cpp @@ -1486,7 +1486,7 @@ auto Interpreter::StepExp() -> ErrorOr { ElementPath::Component member(&access.member(), found_in_interface, witness); const Value* aggregate; - const Value* me_value; + std::optional> me_value; std::optional
lhs_address; if (access.is_type_access()) { aggregate = act.results().back();