diff options
author | Arne Döring <arne.doering@gmx.net> | 2019-05-08 09:36:27 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2019-05-08 09:36:27 +0200 |
commit | 34405db80f5e9e77692fbbf660465b6fb1cd5c4a (patch) | |
tree | 7f142dc3152139d55e69046b0e3af5cf1b24444d /compiler | |
parent | a5fb0acf5f0cd9ea4fcf5ea615006580ae448dfd (diff) | |
download | Nim-34405db80f5e9e77692fbbf660465b6fb1cd5c4a.tar.gz |
forbid casting to bare unchecked array (#11186)
* fixes #11180, forbid casting to unchecked array. * allow UncheckedArray as param
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/types.nim | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/compiler/types.nim b/compiler/types.nim index a40a94421..ce80949b5 100644 --- a/compiler/types.nim +++ b/compiler/types.nim @@ -1199,9 +1199,9 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, case t2.kind of tyVar, tyLent: if taHeap notin flags: result = t2 # ``var var`` is illegal on the heap - of tyOpenArray: + of tyOpenArray, tyUncheckedArray: if kind != skParam: result = t - else: result = typeAllowedAux(marker, t2, kind, flags) + else: result = typeAllowedAux(marker, t2.sons[0], skParam, flags) else: if kind notin {skParam, skResult}: result = t else: result = typeAllowedAux(marker, t2, kind, flags) @@ -1235,14 +1235,21 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind, result = nil of tyOrdinal: if kind != skParam: result = t - of tyGenericInst, tyDistinct, tyAlias, tyInferred, tyUncheckedArray: + of tyGenericInst, tyDistinct, tyAlias, tyInferred: result = typeAllowedAux(marker, lastSon(t), kind, flags) of tyRange: if skipTypes(t.sons[0], abstractInst-{tyTypeDesc}).kind notin {tyChar, tyEnum, tyInt..tyFloat128, tyUInt8..tyUInt32}: result = t of tyOpenArray, tyVarargs, tySink: - if kind != skParam: result = t - else: result = typeAllowedAux(marker, t.sons[0], skVar, flags) + if kind != skParam: + result = t + else: + result = typeAllowedAux(marker, t.sons[0], skVar, flags) + of tyUncheckedArray: + if kind != skParam and taHeap notin flags: + result = t + else: + result = typeAllowedAux(marker, lastSon(t), kind, flags) of tySequence, tyOpt: if t.sons[0].kind != tyEmpty: result = typeAllowedAux(marker, t.sons[0], skVar, flags+{taHeap}) |