diff --git a/compiler/semobjconstr.nim b/compiler/semobjconstr.nim index c9216cc512..1130abef3a 100644 --- a/compiler/semobjconstr.nim +++ b/compiler/semobjconstr.nim @@ -352,6 +352,9 @@ proc semObjConstr(c: PContext, n: PNode, flags: TExprFlags): PNode = t = skipTypes(t.sons[0], {tyGenericInst, tyAlias, tySink, tyOwned}) if optNimV2 in c.config.globalOptions: result.typ = makeVarType(c, result.typ, tyOwned) + # we have to watch out, there are also 'owned proc' types that can be used + # multiple times as long as they don't have closures. + result.typ.flags.incl tfHasOwned if t.kind != tyObject: localError(c.config, n.info, errGenerated, "object constructor needs an object type") return