From 1bb117cd7a49954832d21e6a1502492770acb77b Mon Sep 17 00:00:00 2001 From: metagn Date: Tue, 11 Apr 2023 10:23:41 +0300 Subject: `proc` typeclass accounts for `iterator`, call conventions + `nil` fix + document typeclass AST (#21629) * test fix #16546 #16548 + another issue * please don't tell me other packages do this * fix CI + test typeclass callconv pragma * better logic in parser * docs and changelog --- changelogs/changelog_2_0_0.md | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'changelogs') diff --git a/changelogs/changelog_2_0_0.md b/changelogs/changelog_2_0_0.md index 60b380d12..bef5f6073 100644 --- a/changelogs/changelog_2_0_0.md +++ b/changelogs/changelog_2_0_0.md @@ -175,6 +175,40 @@ - - Added the `--legacy:verboseTypeMismatch` switch to get legacy type mismatch error messages. +- The `proc` and `iterator` type classes now respectively only match + procs and iterators. Previously both type classes matched any of + procs or iterators. + + ```nim + proc prc(): int = + 123 + + iterator iter(): int = + yield 123 + + proc takesProc[T: proc](x: T) = discard + proc takesIter[T: iterator](x: T) = discard + + # always compiled: + takesProc(prc) + takesIter(iter) + # no longer compiles: + takesProc(iter) + takesIter(prc) + ``` + +- The `proc` and `iterator` type classes now accept a calling convention pragma + (i.e. `proc {.closure.}`) that must be shared by matching proc or iterator + types. Previously pragmas were parsed but discarded if no parameter list + was given. + + This is represented in the AST by an `nnkProcTy`/`nnkIteratorTy` node with + an `nnkEmpty` node in the place of the `nnkFormalParams` node, and the pragma + node in the same place as in a concrete `proc` or `iterator` type node. This + state of the AST may be unexpected to existing code, both due to the + replacement of the `nnkFormalParams` node as well as having child nodes + unlike other type class AST. + ## Standard library additions and changes [//]: # "Changes:" -- cgit 1.4.1-2-gfad0