Skip to content

Bug with late Finalizable objects #49005

Closed
@liamappelbe

Description

@liamappelbe

In some cases, a late Finalizable will incorrectly report that it's uninitialized:

import 'dart:ffi';

import 'package:test/test.dart';

class Foo implements Finalizable {
  final int x;
  Foo(this.x);
}

void main() {
  late Foo foo;

  setUpAll(() {
    foo = Foo(123);
  });

  test('check foo', () {
    expect(foo.x, 123);
  });
}
Unhandled exception:
LateInitializationError: Local 'foo' has not been initialized.
#0      LateError._throwLocalNotInitialized (dart:_internal-patch/internal_patch.dart:199:5)
#1      main (late_finalizable.dart)
#2      _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:297:19)
#3      _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)

This test passes if you remove implements Finalizable, or change the variable to Foo? foo;.

cc @dcharkes

Metadata

Metadata

Assignees

Labels

area-core-librarySDK core library issues (core, async, ...); use area-vm or area-web for platform specific libraries.area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-ffi

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions