Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Error: invalid type: 'void' for var" compile error on AsyncHttpClient.downloadFile (devel branch) #16741

Closed
rominf opened this issue Jan 17, 2021 · 2 comments

Comments

@rominf
Copy link
Contributor

rominf commented Jan 17, 2021

Nim from the devel branch doesn't compile simple example with AsyncHttpClient.downloadFile.

Example

import asyncdispatch
import httpclient

proc test_async {.async.} =
  var client = newAsyncHttpClient()
  await client.downloadFile("http://speedtest-ams2.digitalocean.com/10mb.test", "/tmp/10mb.test")
  
waitFor test_async()

Current Output

Hint: used config file '/home/rominf/dev/nim/config/nim.cfg' [Conf]
Hint: used config file '/home/rominf/dev/nim/config/config.nims' [Conf]
................................................
/tmp/test_asynchttpclient_downloadfile_bug.nim(4, 19) template/generic instantiation of `async` from here
/tmp/test_asynchttpclient_downloadfile_bug.nim(6, 15) template/generic instantiation of `downloadFile` from here
/home/rominf/dev/nim/lib/pure/httpclient.nim(1250, 28) template/generic instantiation of `downloadFileEx` from here
/home/rominf/dev/nim/lib/pure/httpclient.nim(1226, 3) Error: invalid type: 'void' for var

Expected Output

[downloaded file]

Possible Solution

If I change httpclient implementation:

-proc downloadFile*(client: AsyncHttpClient, url: Uri | string,
+proc downloadFile*(client: AsyncHttpClient, url: string,

it works again.

$ nim -v
Nim Compiler Version 1.5.1 [Linux: amd64]
Compiled at 2021-01-17
Copyright (c) 2006-2021 by Andreas Rumpf

git hash: 6c07b0a1f8daf96078ae68b83ead1d48675969d7
active boot switches: -d:release
@ghost
Copy link

ghost commented Jan 17, 2021

Seems to be caused by #15919 - on line 1226 there's a generic proc inside of another generic proc, so the compiler doesn't like that (or maybe it's not allowed at all).

One possible solution is to move downloadFileEx out of downloadFile, then it starts working again.

rominf pushed a commit to rominf/Nim that referenced this issue Jan 21, 2021
Move `downloadFileEx` out of `downloadFile` (solution, proposed by
@Yardanico).

Tested manually.
@timotheecour
Copy link
Member

on line 1226 there's a generic proc inside of another generic proc, so the compiler doesn't like that (or maybe it's not allowed at all).

wrong diagnostic, generic inside generic is ok. I just filed #16786 which shows root cause

ardek66 pushed a commit to ardek66/Nim that referenced this issue Mar 26, 2021
Move `downloadFileEx` out of `downloadFile` (solution, proposed by
@Yardanico).

Tested manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants