diff options
author | metagn <metagngn@gmail.com> | 2022-09-14 19:30:15 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-14 18:30:15 +0200 |
commit | a73ae3e066caecb7a891de87cf7c004805f96ff0 (patch) | |
tree | 2cc5172af6584e6546c9f314abfbd908806ac266 /doc | |
parent | 2140d05f34f7976ed7f7058baa952490ee3fb859 (diff) | |
download | Nim-a73ae3e066caecb7a891de87cf7c004805f96ff0.tar.gz |
minor improvements to follow up recent PRs (#20342)
put mOpenArrayToSeq in compile-time evaluation whitelist (it was mNone before which was whitelisted), homogenize "ordinal type expected" errors, put overloadable enums in non-experimental manual
Diffstat (limited to 'doc')
-rw-r--r-- | doc/manual.md | 32 | ||||
-rw-r--r-- | doc/manual_experimental.md | 38 |
2 files changed, 32 insertions, 38 deletions
diff --git a/doc/manual.md b/doc/manual.md index 06930780e..6d92a6dca 100644 --- a/doc/manual.md +++ b/doc/manual.md @@ -1313,6 +1313,38 @@ as `MyEnum.value`: echo MyEnum.amb # OK. ``` +Enum value names are overloadable, much like routines. If both of the enums +`T` and `U` have a member named `foo`, then the identifier `foo` corresponds +to a choice between `T.foo` and `U.foo`. During overload resolution, +the correct type of `foo` is decided from the context. If the type of `foo` is +ambiguous, a static error will be produced. + + ```nim test = "nim c $1" + + type + E1 = enum + value1, + value2 + E2 = enum + value1, + value2 = 4 + + const + Lookuptable = [ + E1.value1: "1", + # no need to qualify value2, known to be E1.value2 + value2: "2" + ] + + proc p(e: E1) = + # disambiguation in 'case' statements: + case e + of value1: echo "A" + of value2: echo "B" + + p value2 + ``` + To implement bit fields with enums see [Bit fields]. diff --git a/doc/manual_experimental.md b/doc/manual_experimental.md index ede2ba02b..9dd44ab3b 100644 --- a/doc/manual_experimental.md +++ b/doc/manual_experimental.md @@ -86,44 +86,6 @@ No Unicode normalization step is performed. pragma `{.experimental: "unicodeOperators".}` reliably. -Overloadable enum value names -============================= - -Enum value names are overloadable, much like routines. If both of the enums -`T` and `U` have a member named `foo`, then the identifier `foo` corresponds -to a choice between `T.foo` and `U.foo`. During overload resolution, -the correct type of `foo` is decided from the context. If the type of `foo` is -ambiguous, a static error will be produced. - - ```nim test = "nim c $1" - - type - E1 = enum - value1, - value2 - E2 = enum - value1, - value2 = 4 - - const - Lookuptable = [ - E1.value1: "1", - # no need to qualify value2, known to be E1.value2 - value2: "2" - ] - - proc p(e: E1) = - # disambiguation in 'case' statements: - case e - of value1: echo "A" - of value2: echo "B" - - p value2 - ``` - -Previously required `{.experimental: "overloadableEnums".}` to enable, -now always enabled. - Top-down type inference ======================= |