Tensegritics / Tensegritics/ClojureDart

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

Open
#339 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Clojure
Stars
1.6k
Forks
119
PR merge metrics
No merged PRs in 30d

Description

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)))

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the three examples in the issue and compare the generated Dart errors, especially with ^:async, return type hints, and await. Trace the compiler handling for these forms; the fix is complete when the affected examples compile with the intended Future return type.

Written by the indexing model from the issue text.

Assessment

Tech stack
clojure, dart, flutter
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.