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

Generic model do not compile #132

Closed
Clonkk opened this issue Jan 20, 2022 · 3 comments · Fixed by #134
Closed

Generic model do not compile #132

Clonkk opened this issue Jan 20, 2022 · 3 comments · Fixed by #134

Comments

@Clonkk
Copy link
Contributor

Clonkk commented Jan 20, 2022

When trying to use generics with ref object of Mode l Iget a compile time error :

/home/rcaillaud/Workspace/localws/norm/src/norm/sqlite.nim(86, 22) template/generic instantiation of `hasCustomPragma` from here
/home/rcaillaud/.choosenim/toolchains/nim-1.6.2/lib/core/macros.nim(1529, 25) Error: node is not a symbol

The problem is easy to reproduce :

import norm/[sqlite, model]
import std/os

type A[T] = ref object of Model
  a: int

putEnv(dbHostEnv, "my.db")

proc main() =
  withDb:
    var a = new(A[int])
    db.createTables(a)

main()

This happens even if the generic parameters is not a field. I know the error actually comes from hasCustomPragmas (you can reproduce outside of norm, so it's not strictly speaking a norm issue) but I was wondering if there was a known solution to this ?

@Clonkk
Copy link
Contributor Author

Clonkk commented Jan 20, 2022

I dig more into this and it is not a Norm limitation - unless Norm implement its own hasCustomPragma proc to solve this.

See nim-lang/Nim#19427 for more info

@Clonkk Clonkk closed this as completed Jan 20, 2022
@Clonkk Clonkk reopened this Jan 25, 2022
@Clonkk
Copy link
Contributor Author

Clonkk commented Jan 25, 2022

Reopening because the current fix devel (nim-lang/Nim#19427) is not sufficient

@Clonkk
Copy link
Contributor Author

Clonkk commented Jan 25, 2022

Follow up that should fix generic model in nim-lang/Nim#19451.

@moigagoo Considering these changes will not land in 1.6.X would you be in favor of a local hasCustomPragma / getCustomPragmaVal fixed (that would be the working devel version) with something like :

when (NimMajor, NimMinor) <= (1, 6):
  import macros except hasCustomPragma, getCustomPragmaVal
  export macros
  #TODO fetch current custom pragmas proc from devel macros.nim
else:
  import macros
  export macros

It's not the prettiest but it would allow generic model in Norm to work with latest Nim LTS.

@moigagoo moigagoo linked a pull request Feb 8, 2022 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant