Skip to content

Commit 967dfe6

Browse files
mkustermannCommit Queue
authored and
Commit Queue
committed
[dart2wasm] Fix compiler bug regarding void values that can be observed
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]>
1 parent 5a38644 commit 967dfe6

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

pkg/dart2wasm/lib/code_generator.dart

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1031,12 +1031,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
10311031

10321032
@override
10331033
void visitVariableDeclaration(VariableDeclaration node) {
1034-
if (node.type is VoidType) {
1035-
if (node.initializer != null) {
1036-
wrap(node.initializer!, voidMarker);
1037-
}
1038-
return;
1039-
}
10401034
w.ValueType type = translateType(node.type);
10411035
w.Local? local;
10421036
Capture? capture = closures.captures[node];
@@ -2166,10 +2160,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
21662160

21672161
@override
21682162
w.ValueType visitVariableGet(VariableGet node, w.ValueType expectedType) {
2169-
// Return `void` for a void [VariableGet].
2170-
if (node.variable.type is VoidType) {
2171-
return voidMarker;
2172-
}
21732163
w.Local? local = locals[node.variable];
21742164
Capture? capture = closures.captures[node.variable];
21752165
if (capture != null) {
@@ -2192,10 +2182,6 @@ class CodeGenerator extends ExpressionVisitor1<w.ValueType, w.ValueType>
21922182

21932183
@override
21942184
w.ValueType visitVariableSet(VariableSet node, w.ValueType expectedType) {
2195-
// Return `void` for a void [VariableSet].
2196-
if (node.variable.type is VoidType) {
2197-
return wrap(node.value, voidMarker);
2198-
}
21992185
w.Local? local = locals[node.variable];
22002186
Capture? capture = closures.captures[node.variable];
22012187
bool preserved = expectedType != voidMarker;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
import 'dart:async';
6+
7+
import 'package:async_helper/async_helper.dart';
8+
import 'package:expect/expect.dart';
9+
10+
void main() async {
11+
asyncStart();
12+
testVoid();
13+
await testFutureVoid();
14+
asyncEnd();
15+
}
16+
17+
void testVoid() {
18+
void x = int.parse('42');
19+
Expect.equals(42, x as dynamic);
20+
}
21+
22+
Future testFutureVoid() async {
23+
final controller = StreamController(onCancel: () async => int.parse('42'));
24+
final subscription = controller.stream.listen(null);
25+
Expect.equals(42, (await subscription.cancel()) as dynamic);
26+
}

0 commit comments

Comments
 (0)