[dart2wasm] Fix compiler bug regarding void values that can be observed

Issue https://github.com/dart-lang/sdk/issues/54800

Change-Id: I26b8c35f60955ee46eeae19797aab7e6c84bf354
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350580
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
This commit is contained in:
Martin Kustermann 2024-02-07 08:05:19 +00:00 committed by Commit Queue
parent 5a38644295
commit 967dfe6547
2 changed files with 26 additions and 14 deletions

View file

@ -1031,12 +1031,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
@override
void visitVariableDeclaration(VariableDeclaration node) {
if (node.type is VoidType) {
if (node.initializer != null) {
wrap(node.initializer!, voidMarker);
}
return;
}
w.ValueType type = translateType(node.type);
w.Local? local;
Capture? capture = closures.captures[node];
@ -2166,10 +2160,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
@override
w.ValueType visitVariableGet(VariableGet node, w.ValueType expectedType) {
// Return `void` for a void [VariableGet].
if (node.variable.type is VoidType) {
return voidMarker;
}
w.Local? local = locals[node.variable];
Capture? capture = closures.captures[node.variable];
if (capture != null) {
@ -2192,10 +2182,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
@override
w.ValueType visitVariableSet(VariableSet node, w.ValueType expectedType) {
// Return `void` for a void [VariableSet].
if (node.variable.type is VoidType) {
return wrap(node.value, voidMarker);
}
w.Local? local = locals[node.variable];
Capture? capture = closures.captures[node.variable];
bool preserved = expectedType != voidMarker;

View file

@ -0,0 +1,26 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'dart:async';
import 'package:async_helper/async_helper.dart';
import 'package:expect/expect.dart';
void main() async {
asyncStart();
testVoid();
await testFutureVoid();
asyncEnd();
}
void testVoid() {
void x = int.parse('42');
Expect.equals(42, x as dynamic);
}
Future testFutureVoid() async {
final controller = StreamController(onCancel: () async => int.parse('42'));
final subscription = controller.stream.listen(null);
Expect.equals(42, (await subscription.cancel()) as dynamic);
}