Skip to content

Commit

Permalink
[dart2wasm] Fix compiler bug regarding void values that can be obse…
Browse files Browse the repository at this point in the history
…rved

Issue #54800

Change-Id: I26b8c35f60955ee46eeae19797aab7e6c84bf354
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/350580
Reviewed-by: Slava Egorov <[email protected]>
Commit-Queue: Martin Kustermann <[email protected]>
  • Loading branch information
mkustermann authored and Commit Queue committed Feb 7, 2024
1 parent 5a38644 commit 967dfe6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 14 deletions.
14 changes: 0 additions & 14 deletions pkg/dart2wasm/lib/code_generator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand Down
26 changes: 26 additions & 0 deletions tests/language/void/regress_54800_test.dart
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit 967dfe6

Please sign in to comment.