[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 <kustermann@google.com> Commit-Queue: Nate Biggs <natebiggs@google.com>
This commit is contained in:
@@ -3256,6 +3256,9 @@ class TearOffCodeGenerator extends AstCodeGenerator {
|
||||
|
||||
b.pushObjectHeaderFields(info);
|
||||
b.local_get(paramLocals[0]); // `this` as context
|
||||
// The closure requires a struct value so box `this` if necessary.
|
||||
translator.convertType(b, paramLocals[0].type,
|
||||
struct.fields[FieldIndex.closureContext].type.unpacked);
|
||||
translator.globals.readGlobal(b, closure.vtable);
|
||||
types.makeType(this, functionType);
|
||||
b.struct_new(struct);
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
// 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 'package:expect/expect.dart';
|
||||
|
||||
void main() {
|
||||
final tearoff = (-4).abs;
|
||||
Expect.equals(tearoff(), 4);
|
||||
}
|
||||
Reference in New Issue
Block a user