This commit is contained in:
Andreas Rumpf
2018-02-11 14:52:19 +01:00
parent 7847cd8759
commit a4deceb134
2 changed files with 46 additions and 2 deletions

View File

@@ -124,6 +124,15 @@ proc pickBestCandidate(c: PContext, headSymbol: PNode,
else:
break
proc effectProblem(f, a: PType; result: var string) =
if f.kind == tyProc and a.kind == tyProc:
if tfThread in f.flags and tfThread notin a.flags:
result.add "\n This expression is not GC-safe. Annotate the " &
"proc with {.gcsafe.} to get extended error information."
elif tfNoSideEffect in f.flags and tfNoSideEffect notin a.flags:
result.add "\n This expression can have side effects. Annotate the " &
"proc with {.noSideEffect.} to get extended error information."
proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
(TPreferedDesc, string) =
var prefer = preferName
@@ -158,15 +167,20 @@ proc presentFailedCandidates(c: PContext, n: PNode, errors: CandidateErrors):
if err.firstMismatch != 0 and n.len > 2:
add(candidates, " first type mismatch at position: " & $err.firstMismatch &
"\n required type: ")
var wanted, got: PType = nil
if err.firstMismatch < err.sym.typ.len:
candidates.add typeToString(err.sym.typ.sons[err.firstMismatch])
wanted = err.sym.typ.sons[err.firstMismatch]
candidates.add typeToString(wanted)
else:
candidates.add "none"
if err.firstMismatch < n.len:
candidates.add "\n but expression '"
candidates.add renderTree(n[err.firstMismatch])
candidates.add "' is of type: "
candidates.add typeToString(n[err.firstMismatch].typ)
got = n[err.firstMismatch].typ
candidates.add typeToString(got)
if wanted != nil and got != nil:
effectProblem(wanted, got, candidates)
candidates.add "\n"
elif err.unmatchedVarParam != 0 and err.unmatchedVarParam < n.len:
add(candidates, "for a 'var' type a variable needs to be passed, but '" &

View File

@@ -0,0 +1,30 @@
discard """
cmd: "nim check $file"
errormsg: "type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>"
nimout: '''
type mismatch: got <AsyncHttpServer, Port, proc (req: Request): Future[system.void]{.locks: <unknown>.}>
but expected one of:
proc serve(server: AsyncHttpServer; port: Port;
callback: proc (request: Request): Future[void]; address = ""): Future[void]
first type mismatch at position: 3
required type: proc (request: Request): Future[system.void]{.closure, gcsafe.}
but expression 'cb' is of type: proc (req: Request): Future[system.void]{.locks: <unknown>.}
This expression is not GC-safe. Annotate the proc with {.gcsafe.} to get extended error information.
expression: serve(server, Port(7898), cb)
'''
"""
# bug #6186
import asyncdispatch, asynchttpserver
var server = newAsyncHttpServer()
var foo = "foo"
proc cb(req: Request) {.async.} =
var baa = foo & "asds"
await req.respond(Http200, baa)
asyncCheck server.serve(Port(7898), cb )
runForever()