Araq / ormin

Ormin -- An ORM for Nim.
MIT License
153 stars 18 forks source link

type expected, but got: nil #19

Open kidandcat opened 5 years ago

kidandcat commented 5 years ago
import ormin / [serverws]
import ormin

import json

importModel(DbBackend.sqlite, "chat_model")

#var db {.global.} = open("chat_ormin.db", "", "", "")

protocol "pingclient.nim":
  server "ping":
    echo "got ping"
    send(%1)

  client "ping":
    proc ping*() {.exportc.}
    var res: int
    res = recv()
    echo "got " & $res

serve "ormin", dispatch

In the chat example you don't specify the type to recv()

PD: it works if I use recv(int)

Araq commented 5 years ago

Is that a documentation/example bug?

kidandcat commented 5 years ago

I suppose yes, but if you tell me it should work without the typing.... I'm not sure if recv() can infer the type from the variable you are assigning to.

If it's a doc bug, I'll fix it by PR.

Araq commented 5 years ago

Hmm, I don't remember Ormin's code base. :D Stay tuned.

Araq commented 5 years ago

So ... forumproto.nim contains this code:


  client:
    type Session = ref object
    var gSessions: seq[Session]
    gSessions = recv()
    proc getAllSessions()

And to the best of my knowledge this test is green. recv() here uses the seq[ of the previously type as defined in the type section ].