diff options
author | Araq <rumpf_a@web.de> | 2019-09-08 09:22:11 +0200 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2019-09-08 13:08:41 +0200 |
commit | 8362d92e47cb3dda451829223a28a77947f1f68d (patch) | |
tree | abf0aad3fbfe36914b581a69d81408615775fda2 | |
parent | 4bbafb47dc87f3742ecb2059d7dac9b2d06fcc11 (diff) | |
download | Nim-8362d92e47cb3dda451829223a28a77947f1f68d.tar.gz |
fixes #12091
-rw-r--r-- | compiler/semtypes.nim | 10 |
1 files changed, 9 insertions, 1 deletions
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`, |