Skip to content

Misleading error when trying to spawn an isolate from a function which accesses local variables #48346

@jakemac53

Description

@jakemac53

Repro program:

import 'dart:async';
import 'dart:isolate';

void main() async {
  var i = 0;
  void childIsolateFn(SendPort sendPort) {
    sendPort.send(i);
  }

  var receivePort = ReceivePort();
  var isolate = await Isolate.spawn(childIsolateFn, receivePort.sendPort);
}

This fails with the error Invalid argument(s): Illegal argument in isolate message: (object is aReceivePort).

It seems valid that you can't refer to local variables in this case - but the error is very misleading and doesn't help you to diagnose the actual problem.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-vmUse area-vm for VM related issues, including code coverage, and the AOT and JIT backends.library-isolate

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions