nim-chronos icon indicating copy to clipboard operation
nim-chronos copied to clipboard

async transformation doesn't handle implicit return

Open arnetheduck opened this issue 5 years ago • 1 comments

proc works(): Future[int] {.async.} =
  return 53

proc works2(): Future[int] {.async.} =
  result = 53

proc broken(): Future[int] {.async.} =
  53 # Error: expression '53' is of type 'int literal(53)' and has to be discarded

1357045cfa67dc9ca8299b36abab627a1de25511

arnetheduck avatar Mar 26 '19 16:03 arnetheduck

This is very old known issue.

Because async macro is working with untyped arguments its impossible to fix it properly.

For example, if we are going to replace all unattended values with result = <unattended value> we can go to this problem:

proc empty() {.async.} =
  discard

proc notBrokenAnymore(): Future[int] {.async.} =
  await works()

proc notBrokenAnymore(): Future[int] {.async.} =
  53

proc nowBecomeBroken(): Future[int] {.async.} =
  await empty()

Because i can't check type of empty() i can't make transformation properly.

cheatfate avatar Mar 27 '19 08:03 cheatfate

Fixed in https://github.com/status-im/nim-chronos/pull/401

arnetheduck avatar Dec 21 '23 14:12 arnetheduck