diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2021-09-24 16:27:34 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-24 16:27:34 +0200 |
commit | 7e5eab571e6e8e57928b40f535802aec04e04633 (patch) | |
tree | 5bb62ae41c87a6492ec8593400d1d1b238a03c70 | |
parent | f7d642f2f3925feb5addc315eb59caf326cad470 (diff) | |
download | Nim-7e5eab571e6e8e57928b40f535802aec04e04633.tar.gz |
closes #18690; make view types stricter [backport] (#18891)
* closes #18690 * don't allow capturing of view types [backport]
-rw-r--r-- | compiler/lambdalifting.nim | 6 | ||||
-rw-r--r-- | tests/views/tviews1.nim | 13 |
2 files changed, 14 insertions, 5 deletions
diff --git a/compiler/lambdalifting.nim b/compiler/lambdalifting.nim index c555cedfe..a622f6de6 100644 --- a/compiler/lambdalifting.nim +++ b/compiler/lambdalifting.nim @@ -12,7 +12,7 @@ import intsets, strutils, options, ast, astalgo, msgs, idents, renderer, types, magicsys, lowerings, tables, modulegraphs, lineinfos, - transf, liftdestructors + transf, liftdestructors, typeallowed discard """ The basic approach is that captured vars need to be put on the heap and @@ -191,9 +191,7 @@ proc interestingVar(s: PSym): bool {.inline.} = s.typ.kind notin {tyStatic, tyTypeDesc} proc illegalCapture(s: PSym): bool {.inline.} = - result = skipTypes(s.typ, abstractInst).kind in - {tyVar, tyOpenArray, tyVarargs, tyLent} or - s.kind == skResult + result = classifyViewType(s.typ) != noView or s.kind == skResult proc isInnerProc(s: PSym): bool = if s.kind in {skProc, skFunc, skMethod, skConverter, skIterator} and s.magic == mNone: diff --git a/tests/views/tviews1.nim b/tests/views/tviews1.nim index 49d79c5b5..3dbf664fc 100644 --- a/tests/views/tviews1.nim +++ b/tests/views/tviews1.nim @@ -6,7 +6,8 @@ discard """ 2 3 3 -15''' +15 +(oa: [1, 3, 4])''' targets: "c cpp" """ @@ -38,3 +39,13 @@ var y: var int = foo(x) y = 15 echo foo(x) # bug #16132 + +# bug #18690 + +type + F = object + oa: openarray[int] + +let s1 = @[1,3,4,5,6] +var test = F(oa: toOpenArray(s1, 0, 2)) +echo test |