Skip to content

Commit

Permalink
fixes nim-lang#15671 [backport:1.4] (nim-lang#15690)
Browse files Browse the repository at this point in the history
* fixes nim-lang#15671 [backport:1.4]

* progress
  • Loading branch information
Araq authored and ringabout committed Nov 25, 2020
1 parent 8a11772 commit b54eff3
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions compiler/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = nil
if typ == nil: return nil
if containsOrIncl(marker, typ.id): return nil
var t = skipTypes(typ, abstractInst-{tyTypeDesc})
var t = skipTypes(typ, abstractInst-{tyTypeDesc, tySink})
case t.kind
of tyVar, tyLent:
if kind in {skProc, skFunc, skConst} and (views notin c.features):
result = t
elif t.kind == tyLent and kind != skResult and (views notin c.features):
result = t
else:
var t2 = skipTypes(t[0], abstractInst-{tyTypeDesc})
var t2 = skipTypes(t[0], abstractInst-{tyTypeDesc, tySink})
case t2.kind
of tyVar, tyLent:
if taHeap notin flags: result = t2 # ``var var`` is illegal on the heap
Expand All @@ -70,6 +70,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
of tyUncheckedArray:
if kind != skParam and views notin c.features: result = t
else: result = typeAllowedAux(marker, t2[0], kind, c, flags)
of tySink:
result = t
else:
if kind notin {skParam, skResult} and views notin c.features: result = t
else: result = typeAllowedAux(marker, t2, kind, c, flags)
Expand Down Expand Up @@ -125,12 +127,18 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
result = t
else:
result = typeAllowedAux(marker, t[0], kind, c, flags+{taIsOpenArray})
of tyVarargs, tySink:
of tyVarargs:
# you cannot nest openArrays/sinks/etc.
if kind != skParam or taIsOpenArray in flags:
result = t
else:
result = typeAllowedAux(marker, t[0], kind, c, flags+{taIsOpenArray})
of tySink:
# you cannot nest openArrays/sinks/etc.
if kind != skParam or taIsOpenArray in flags or t[0].kind in {tySink, tyLent, tyVar}:
result = t
else:
result = typeAllowedAux(marker, t[0], kind, c, flags)
of tyUncheckedArray:
if kind != skParam and taHeap notin flags:
result = t
Expand Down

0 comments on commit b54eff3

Please sign in to comment.