This commit is contained in:
Andreas Rumpf
2016-01-05 10:20:24 +01:00
parent 164ebb6762
commit 1a2bda45ec
3 changed files with 63 additions and 5 deletions

View File

@@ -162,9 +162,9 @@ proc addHiddenParam(routine: PSym, param: PSym) =
# some nkEffect node:
param.position = routine.typ.n.len-1
addSon(params, newSymNode(param))
incl(routine.typ.flags, tfCapturesEnv)
#incl(routine.typ.flags, tfCapturesEnv)
assert sfFromGeneric in param.flags
#echo "produced environment: ", param.id, " for ", routine.name.s
#echo "produced environment: ", param.id, " for ", routine.id
proc getHiddenParam(routine: PSym): PSym =
let params = routine.ast.sons[paramsPos]

View File

@@ -958,15 +958,17 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode =
var n = n
let original = n.sons[namePos].sym
let s = copySym(original, false)
incl(s.flags, sfFromGeneric)
let s = original #copySym(original, false)
#incl(s.flags, sfFromGeneric)
#s.owner = original
n = replaceTypesInBody(c, pt, n, original)
result = n
s.ast = result
n.sons[namePos].sym = s
n.sons[genericParamsPos] = emptyNode
let params = n.typ.n
# for LL we need to avoid wrong aliasing
let params = copyTree n.typ.n
n.sons[paramsPos] = params
s.typ = n.typ
for i in 1..<params.len:
@@ -974,6 +976,7 @@ proc semInferredLambda(c: PContext, pt: TIdTable, n: PNode): PNode =
tyFromExpr, tyFieldAccessor}+tyTypeClasses:
localError(params[i].info, "cannot infer type of parameter: " &
params[i].sym.name.s)
#params[i].sym.owner = s
openScope(c)
pushOwner(s)
addParams(c, params, skProc)

55
tests/async/tlambda.nim Normal file
View File

@@ -0,0 +1,55 @@
# bug 2007
import asyncdispatch, asyncnet, logging, json, uri, strutils, future
type
Builder = ref object
client: Client
build: Build
ProgressCB* = proc (message: string): Future[void] {.closure, gcsafe.}
Build* = ref object
onProgress*: ProgressCB
Client = ref ClientObj
ClientObj = object
onMessage: proc (client: Client, msg: JsonNode): Future[void]
proc newClient*(name: string,
onMessage: (Client, JsonNode) -> Future[void]): Client =
new result
result.onMessage = onMessage
proc newBuild*(onProgress: ProgressCB): Build =
new result
result.onProgress = onProgress
proc start(build: Build, repo, hash: string) {.async.} =
let path = repo.parseUri().path.toLower()
proc onProgress(builder: Builder, message: string) {.async.} =
debug($message)
proc onMessage(builder: Builder, message: JsonNode) {.async.} =
debug("onMessage")
proc newBuilder(): Builder =
var cres: Builder
new cres
cres.client = newClient("builder", (client, msg) => (onMessage(cres, msg)))
cres.build = newBuild(
proc (msg: string): Future[void] {.closure, gcsafe.} = onProgress(cres, msg))
return cres
proc main() =
# Set up logging.
var console = newConsoleLogger(fmtStr = verboseFmtStr)
addHandler(console)
var builder = newBuilder()
main()