Skip to content

Typehinting async functions before arg vector doesn't (always) work #339

Description

@okmaybenot

Describe the bug

Examples:

This one works

(defn async-int ^#/(Future int) []
  (dasync/Future.value 1))

This one doesn't

(defn ^:async async-int ^#/(Future int) []
  (dasync/Future.value 1))
Error: A value of type 'FutureOr<Future<int>>' can't be returned from an async function with return type 'Future<int>'.
 - 'Future' is from 'dart:async'.
return ((da.Future.value(1, )) as da.FutureOr<dc.Future<dc.int>>);

Also, sometimes removing ^:async doesn't help:

(defn async-int-after-job ^#/(Future int) []
  (let [value 1
        job (dasync/Future.value true)]
    (await job)
    (dasync/Future.value value)))
Error: A value of type 'FutureOr<Future<int>>' can't be returned from an async function with return type 'Future<int>'.
 - 'Future' is from 'dart:async'.
return ($1 as da.FutureOr<dc.Future<dc.int>>);

But removing type hint (or moving it before name) helps

(defn ^#/(Future int) async-int-after-job []
  (let [value 1
        job (dasync/Future.value true)]
    (await job)
    (dasync/Future.value value)))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions