Skip to content

Conversation

@liamappelbe
Copy link
Contributor

Unit is a singleton sentinel used by Kotlin when translating suspend funcs that return void into Java methods. It's needed because Java doesn't support void as a generic type param, so various internal objects like Continuation<T> are represented as Continuation<Unit> instead of Continuation<void>.

This PR special cases Unit in the return type of a suspend function to code gen as Future<void> instead of Future<JObject>. Same for interfaces with void suspend functions.

Ordinary functions that return void are translated directly into Java methods that return void, so already return void in Dart land. Also, Unit is a real object, so it could conceivably be passed as a param to a method etc. So this special casing should only be applied to the return type of suspend functions.

Fixes #2876

@github-actions
Copy link

github-actions bot commented Jan 5, 2026

PR Health

License Headers ✔️
// Copyright (c) 2026, 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.
Files
no missing headers

All source files should start with a license header.

Unrelated files missing license headers
Files
pkgs/hooks_runner/test_data/download_assets/hook/build.dart
pkgs/jni/test/debug_release_test.dart
pkgs/objective_c/example/command_line/lib/main.dart
pkgs/objective_c/lib/src/ns_input_stream.dart

This check can be disabled by tagging the PR with skip-license-check.

API leaks ✔️

The following packages contain symbols visible in the public API, but not exported by the library. Export these symbols or remove them from your publicly visible API.

Package Leaked API symbol Leaking sources

This check can be disabled by tagging the PR with skip-leaking-check.

Breaking changes ⚠️
Package Change Current Version New Version Needed Version Looking good?
jni Breaking 0.15.2 0.15.3-wip 0.16.0
Got "0.15.3-wip" expected >= "0.16.0" (breaking changes)
⚠️

This check can be disabled by tagging the PR with skip-breaking-check.

@coveralls
Copy link

Coverage Status

coverage: 81.234% (-0.01%) from 81.248%
when pulling be44e7f on jnigen_unit_type
into 3495c21 on main.

@liamappelbe liamappelbe requested a review from dcharkes January 5, 2026 07:26
@liamappelbe liamappelbe marked this pull request as ready for review January 5, 2026 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

jnigen generates Future<JObject> instead of Future<void> for Kotlin suspend fun with no return type

2 participants