Skip to content

Commit 2c94e56

Browse files
liamappelbecommit-bot@chromium.org
authored and
commit-bot@chromium.org
committed
[vm] Implementation of the null check instruction in the flow graph.
tests/language_2/nnbd/syntax/non_null_assertion_test.dart now passes Bug: #38840 Change-Id: Ie9676583c2cd7434dbb1c4c8b5ee4db817d01228 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121820 Reviewed-by: Alexander Markov <alexmarkov@google.com> Commit-Queue: Liam Appelbe <liama@google.com>
1 parent c0a46e7 commit 2c94e56

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

runtime/vm/compiler/frontend/kernel_binary_flowgraph.cc

+5-3
Original file line numberDiff line numberDiff line change
@@ -3325,9 +3325,11 @@ Fragment StreamingFlowGraphBuilder::BuildNullCheck(TokenPosition* p) {
33253325
if (p != nullptr) *p = position;
33263326

33273327
TokenPosition operand_position = TokenPosition::kNoSource;
3328-
Fragment instructions =
3329-
BuildExpression(&operand_position); // read expression.
3330-
// TODO(37479): Implement null-check semantics.
3328+
Fragment instructions = BuildExpression(&operand_position);
3329+
LocalVariable* expr_temp = MakeTemporary();
3330+
instructions += CheckNull(position, expr_temp, String::null_string(),
3331+
/* clear_the_temp = */ false);
3332+
33313333
return instructions;
33323334
}
33333335

runtime/vm/runtime_entry.cc

+11
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,17 @@ DEFINE_RUNTIME_ENTRY(RangeError, 2) {
153153
}
154154

155155
static void NullErrorHelper(Zone* zone, const String& selector) {
156+
// If the selector is null, this must be a null check that wasn't due to a
157+
// method invocation, so was due to the null check operator.
158+
if (selector.IsNull()) {
159+
const Array& args = Array::Handle(zone, Array::New(4));
160+
args.SetAt(
161+
3, String::Handle(
162+
zone, String::New("Null check operator used on a null value")));
163+
Exceptions::ThrowByType(Exceptions::kCast, args);
164+
return;
165+
}
166+
156167
InvocationMirror::Kind kind = InvocationMirror::kMethod;
157168
if (Field::IsGetterName(selector)) {
158169
kind = InvocationMirror::kGetter;

0 commit comments

Comments
 (0)