diff options
Diffstat (limited to 'compiler/semexprs.nim')
-rw-r--r-- | compiler/semexprs.nim | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/compiler/semexprs.nim b/compiler/semexprs.nim index 9e3e5e076..f39603c0e 100644 --- a/compiler/semexprs.nim +++ b/compiler/semexprs.nim @@ -125,11 +125,18 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus = var s = src if s.kind in tyUserTypeClasses and s.isResolvedUserTypeClass: s = s.lastSon - s = skipTypes(s, abstractVar-{tyTypeDesc}) - var pointers = 0 - while (d != nil) and (d.kind in {tyPtr, tyRef, tyOwned}) and (d.kind == s.kind): - d = d.lastSon + s = skipTypes(s, abstractVar-{tyTypeDesc, tyOwned}) + if s.kind == tyOwned and d.kind != tyOwned: s = s.lastSon + var pointers = 0 + while (d != nil) and (d.kind in {tyPtr, tyRef, tyOwned}): + if s.kind == tyOwned and d.kind != tyOwned: + s = s.lastSon + elif d.kind != s.kind: + break + else: + d = d.lastSon + s = s.lastSon inc pointers if d == nil: result = convNotLegal @@ -143,7 +150,7 @@ proc checkConvertible(c: PContext, castDest, src: PType): TConvStatus = # we use d, s here to speed up that operation a bit: case cmpTypes(c, d, s) of isNone, isGeneric: - if not compareTypes(castDest.skipTypes(abstractVar), src, dcEqIgnoreDistinct): + if not compareTypes(castDest.skipTypes(abstractVar), src.skipTypes({tyOwned}), dcEqIgnoreDistinct): result = convNotLegal else: discard @@ -851,7 +858,7 @@ proc semIndirectOp(c: PContext, n: PNode, flags: TExprFlags): PNode = semOpAux(c, n) var t: PType = nil if n.sons[0].typ != nil: - t = skipTypes(n.sons[0].typ, abstractInst-{tyTypeDesc}) + t = skipTypes(n.sons[0].typ, abstractInst+{tyOwned}-{tyTypeDesc}) if t != nil and t.kind == tyProc: # This is a proc variable, apply normal overload resolution let m = resolveIndirectCall(c, n, nOrig, t) @@ -2421,6 +2428,9 @@ proc semExpr(c: PContext, n: PNode, flags: TExprFlags = {}): PNode = markIndirect(c, result.sym) # if isGenericRoutine(result.sym): # localError(c.config, n.info, errInstantiateXExplicitly, s.name.s) + # "procs literals" are 'owned' + if optNimV2 in c.config.globalOptions: + result.typ = makeVarType(c, result.typ, tyOwned) else: result = semSym(c, n, s, flags) of nkSym: |