Skip to content

Commit d82e84c

Browse files
natebiggsCommit Queue
authored andcommitted
[dart2wasm] Fix tearoff codegen on boxed types.
The struct type for closures requires the context value be a struct. If the tearoff is on an unboxed value, it first has to be boxed before being used to create the closure struct. The new test currently fails at runtime (or via assertions at compile time) with this error: "BoxedInt.abs tear-off" failed: struct.new[2] expected type (ref struct), found local.get of type i64 Change-Id: Ie861bc12a34b21f8b3415edadf55ce3d59f97580 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/402560 Reviewed-by: Martin Kustermann <[email protected]> Commit-Queue: Nate Biggs <[email protected]>
1 parent 0a01346 commit d82e84c

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

pkg/dart2wasm/lib/code_generator.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3256,6 +3256,9 @@ class TearOffCodeGenerator extends AstCodeGenerator {
32563256

32573257
b.pushObjectHeaderFields(info);
32583258
b.local_get(paramLocals[0]); // `this` as context
3259+
// The closure requires a struct value so box `this` if necessary.
3260+
translator.convertType(b, paramLocals[0].type,
3261+
struct.fields[FieldIndex.closureContext].type.unpacked);
32593262
translator.globals.readGlobal(b, closure.vtable);
32603263
types.makeType(this, functionType);
32613264
b.struct_new(struct);
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 'package:expect/expect.dart';
6+
7+
void main() {
8+
final tearoff = (-4).abs;
9+
Expect.equals(tearoff(), 4);
10+
}

0 commit comments

Comments
 (0)