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: undeclared identifier: 'log' #52

Closed
syhpoon opened this issue Mar 29, 2019 · 3 comments
Closed

Error: undeclared identifier: 'log' #52

syhpoon opened this issue Mar 29, 2019 · 3 comments

Comments

@syhpoon
Copy link

syhpoon commented Mar 29, 2019

Hey guys,

I'm trying to incorporate chronicles into my library and found a weird compilation-time error.
After stripping all the nonrelevant parts, this is what I've got:

file a.nim:

import                                                                                             
   asyncdispatch,                                                                                  
   chronicles                                                                                      
                                                                                                   
type                                                                                               
   Wut*[P] = ref object                                                                            
      ps: seq[P]                                                                                   
                                                                                                   
proc newWut*[P](ps: seq[P]): Wut[P] =                                                              
   Wut[P](ps: ps)                                                                                  
                                                                                                   
proc action(d: Wut) {.async.} =                                                                    
   error "ERROR"                                                                                   
   #echo("ERROR")                                                                                  
                                                                                                   
proc runForever*(d: Wut) {.async.} =                                                               
   while true:                                                                                     
      asyncCheck d.action()

and file main.nim:

import asyncdispatch                                                                               
import a                                                                                           
                                                                                                   
let d = newWut[int](@[1])                                                                          
                                                                                                   
asyncCheck d.runForever()                                                                          
runForever()

when running nim c main.nim, I'm getting the following error:

main.nim(6, 13) template/generic instantiation from here
a.nim(18, 19) template/generic instantiation from here
a.nim(13, 10) template/generic instantiation from here
/home/user/.nimble/pkgs/chronicles-0.5.1/chronicles.nim(344, 5) Error: undeclared identifier: 'log'

If I replace error "ERROR" with echo("ERROR"), everything compiles successfully.
My nim version is:

Compiled at 2019-02-01
Copyright (c) 2006-2018 by Andreas Rumpf

git hash: b6d96cafc8bcad1f3d32f2910b25cd11a93f7751
active boot switches: -d:release```  
@zah
Copy link
Contributor

zah commented Mar 29, 2019

This is a known Nim issue related to the fact that the functions proc runForever*(d: Wut) and proc action(d: Wut) are generic. Nim has some issues with generic symbol look-ups inside modules that are "sandwiched" between the outermost instantiation scope (main.nim) and the innermost non-generic resolved call (chronicles.nim). I'm sorry if this explanation is a bit vague and hard to follow, but the short version of the story is that you can fix the problem by importing chronicles in main.nim:

import asyncdispatch, chronicles 
import a  

let d = newWut[int](@[1])   

asyncCheck d.runForever()
runForever()

@syhpoon
Copy link
Author

syhpoon commented Mar 29, 2019

Thank you, @zah ! Now it works.

@syhpoon syhpoon closed this as completed Mar 29, 2019
@zah
Copy link
Contributor

zah commented May 11, 2019

The underlying Nim issue will be tracked here:
nim-lang/Nim#11225

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

No branches or pull requests

2 participants