From 8362d92e47cb3dda451829223a28a77947f1f68d Mon Sep 17 00:00:00 2001 From: Araq Date: Sun, 8 Sep 2019 09:22:11 +0200 Subject: [PATCH] fixes #12091 --- compiler/semtypes.nim | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/compiler/semtypes.nim b/compiler/semtypes.nim index 151318670..5655479e9 100644 --- a/compiler/semtypes.nim +++ b/compiler/semtypes.nim @@ -850,6 +850,7 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = localError(c.config, n.info, "type '$1 void' is not allowed" % kindToStr[kind]) result = newOrPrevType(kind, prev, c) var isNilable = false + var isOwned = false # check every except the last is an object: for i in isCall .. n.len-2: let ni = n[i] @@ -857,7 +858,9 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = isNilable = true else: let region = semTypeNode(c, ni, nil) - if region.skipTypes({tyGenericInst, tyAlias, tySink}).kind notin { + if region.kind == tyOwned: + isOwned = true + elif region.skipTypes({tyGenericInst, tyAlias, tySink}).kind notin { tyError, tyObject}: message c.config, n[i].info, errGenerated, "region needs to be an object type" else: @@ -867,6 +870,11 @@ proc semAnyRef(c: PContext; n: PNode; kind: TTypeKind; prev: PType): PType = if tfPartial in result.flags: if result.lastSon.kind == tyObject: incl(result.lastSon.flags, tfPartial) #if not isNilable: result.flags.incl tfNotNil + if isOwned and optNimV2 in c.config.globalOptions: + let t = newTypeS(tyOwned, c) + t.flags.incl tfHasOwned + t.rawAddSonNoPropagationOfTypeFlags result + result = t proc findEnforcedStaticType(t: PType): PType = # This handles types such as `static[T] and Foo`,