Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disallow sink openArray[T] types #544

Draft
wants to merge 1 commit into
base: devel
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion compiler/ast/report_enums.nim
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ type
rsemCannotMixTypesAndValuesInTuple
rsemExpectedTypelessDeferBody
rsemInvalidBindContext
rsemCannotCreateImplicitOpenarray
rsemCannotAssignToDiscriminantWithCustomDestructor
rsemUnavailableTypeBound

Expand Down
3 changes: 0 additions & 3 deletions compiler/front/cli_reporter.nim
Original file line number Diff line number Diff line change
Expand Up @@ -2056,9 +2056,6 @@ proc reportBody*(conf: ConfigRef, r: SemReport): string =
"destructor.\nIt is best to factor out piece of object that needs " &
"custom destructor into separate object or not use discriminator assignment"

of rsemCannotCreateImplicitOpenarray:
result = "cannot create an implicit openArray copy to be passed to a sink parameter"

of rsemWrongNumberOfQuoteArguments:
assert false, "UNUSED"

Expand Down
4 changes: 0 additions & 4 deletions compiler/sem/injectdestructors.nim
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,6 @@ proc passCopyToSink(n: PNode; c: var Con; s: var Scope): PNode =
if c.graph.config.selectedGC in {gcArc, gcOrc}:
assert(not containsManagedMemory(n.typ))

if n.typ.skipTypes(abstractInst).kind in {tyOpenArray, tyVarargs}:
localReport(c.graph.config, n.info, reportAst(
rsemCannotCreateImplicitOpenarray, n))

result.add newTree(nkAsgn, tmp, p(n, c, s, normal))
# Since we know somebody will take over the produced copy, there is
# no need to destroy it.
Expand Down
3 changes: 2 additions & 1 deletion compiler/sem/typeallowed.nim
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ proc typeAllowedAux(marker: var IntSet, typ: PType, kind: TSymKind,
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}:
if kind != skParam or taIsOpenArray in flags or
t[0].kind in {tySink, tyLent, tyVar, tyOpenArray}:
result = t
else:
result = typeAllowedAux(marker, t[0], kind, c, flags)
Expand Down
10 changes: 5 additions & 5 deletions tests/lang_objects/destructor/tmove_objconstr.nim
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,9 @@ type
TableNonCopyable = object
x: seq[(string, MySeqNonCopyable)]

proc toTable(pairs: sink openArray[(string, MySeqNonCopyable)]): TableNonCopyable =
discard


let mytable = {"a": newMySeq(2, 5.0)}.toTable
# XXX: ``sink openArray[T]`` is currently disallowed
when false:
proc toTable(pairs: sink openArray[(string, MySeqNonCopyable)]): TableNonCopyable =
discard

let mytable = {"a": newMySeq(2, 5.0)}.toTable