summary refs log tree commit diff stats
path: root/tests/enum
Commit message (Collapse)AuthorAgeFilesLines
* don't require symbol with enum type to be constant in fitNode (#23999)metagn2024-08-221-0/+7
| | | | | | | | | | | | | | | | fixes #23998 In `fitNode` the first symbol of a symchoice that expects an enum type with the same enum type is given as the result of the `fitNode`. But `getConstExpr` is also called on it, which will return a `nil` node for nodes that aren't constant but have the enum type, like variables or proc parameters. Instead we just return the node directly since it's already typed. Normally, this `if` branch in `fitNode` shouldn't exist since `paramTypesMatch` handles it, but the way pure enum symbols work makes it really impractical to check their ambiguity, which `paramTypesMatch` won't like. If it causes problems for regular enums we can restrict this branch to just pure enums until they are hopefully eventually removed.
* always lookup pure enum symbols if expected type is enum (#23976)metagn2024-08-171-0/+13
| | | | | | | | | | | | | | | | | | | | fixes #23689 Normally pure enum symbols only "exist" in lookup if nothing else with the same name is in scope. But if an expression is expected to be an enum type, we know that ambiguity can be resolved between different symbols based on their type, so we can include the normally inaccessible pure enum fields in the ambiguity resolution in the case that the expected enum type is actually a pure enum. This handles the use case in the issue of the type inference for enums reverted in #23588. I know pure enums are supposed to be on their way out so this might seem excessive, but the `pure` pragma can't be removed in the code in the issue due to a redefinition error, they have to be separated into different modules. Normal enums can still resolve the ambiguity here though. I always think about making a list of all the remaining use cases for pure enums and I always forget. Will close #23694 if CI passes
* re-enable tests (#23591)ringabout2024-05-101-4/+2
|
* unordered enum for better interoperability with C (#23585)ringabout2024-05-102-0/+93
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ref https://forum.nim-lang.org/t/11564 ```nim block: # unordered enum block: type unordered_enum = enum a = 1 b = 0 doAssert (ord(a), ord(b)) == (1, 0) block: type unordered_enum = enum a = 1 b = 0 c doAssert (ord(a), ord(b), ord(c)) == (1, 0, 2) block: type unordered_enum = enum a = 100 b c = 50 d doAssert (ord(a), ord(b), ord(c), ord(d)) == (100, 101, 50, 51) block: type unordered_enum = enum a = 7 b = 6 c = 5 d doAssert (ord(a), ord(b), ord(c), ord(d)) == (7, 6, 5, 8) ```
* ambiguous identifier resolution (#23123)metagn2024-01-012-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23002, fixes #22841, refs comments in #23097 When an identifier is ambiguous in scope (i.e. multiple imports contain symbols with the same name), attempt resolving it through type inference (by creating a symchoice). To do this efficiently, `qualifiedLookUp` had to be broken up so that `semExpr` can access the ambiguous candidates directly (now obtained directly via `lookUpCandidates`). This fixes the linked issues, but an example like: ```nim let on = 123 {.warning[ProveInit]: on.} ``` will still fail, since `on` is unambiguously the local `let` symbol here (this is also true for `proc on` but `proc` symbols generate symchoices anyway). Type symbols are not considered to not confuse the type inference. This includes the change in sigmatch, up to this point symchoices with nonoverloadable symbols could be created, they just wouldn't be considered during disambiguation. Now every proper symbol except types are considered in disambiguation, so the correct symbols must be picked during the creation of the symchoice node. I remember there being a violating case of this in the compiler, but this was very likely fixed by excluding type symbols as CI seems to have found no issues. The pure enum ambiguity test was disabled because ambiguous pure enums now behave like overloadable enums with this behavior, so we get a longer error message for `echo amb` like `type mismatch: got <MyEnum | OtherEnum> but expected T`
* Don't try and get enum value if its invalid (#22997)Jake Leahy2023-11-281-0/+8
| | | | | | | | | | | | | | | | | | Currently running `nimsuggest`/`check` on this code causes the compiler to raise an exception ```nim type Test = enum A = 9.0 ``` ``` assertions.nim(34) raiseAssert Error: unhandled exception: int128.nim(69, 11) `arg.sdata(3) == 0` out of range [AssertionDefect] ``` Issue was the compiler still trying to get the ordinal value even if it wasn't an ordinal
* make expressions opt in to symchoices (#22716)metagn2023-09-181-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | refs #22605 Sym choice nodes are now only allowed to pass through semchecking if contexts ask for them to (with `efAllowSymChoice`). Otherwise they are resolved or treated as ambiguous. The contexts that can receive symchoices in this PR are: * Call operands and addresses and emulations of such, which will subject them to overload resolution which will resolve them or fail. * Type conversion operands only for routine symchoices for type disambiguation syntax (like `(proc (x: int): int)(foo)`), which will resolve them or fail. * Proc parameter default values both at the declaration and during generic instantiation, which undergo type narrowing and so will resolve them or fail. This means unless these contexts mess up sym choice nodes should never leave the semchecking stage. This serves as a blueprint for future improvements to intermediate symbol resolution. Some tangential changes are also in this PR: 1. The `AmbiguousEnum` hint is removed, it was always disabled by default and since #22606 it only started getting emitted after the symchoice was soundly resolved. 2. Proc setter syntax (`a.b = c` becoming `` `b=`(a, c) ``) used to fully type check the RHS before passing the transformed call node to proc overloading. Now it just passes the original node directly so proc overloading can deal with its typechecking.
* resolve unambiguous enum symchoices from local scope, error on rest (#22606)metagn2023-09-032-8/+26
| | | | | | | | | | | | | | | | fixes #22598, properly fixes #21887 and fixes test case issue number When an enum field sym choice has to choose a type, check if its name is ambiguous in the local scope, then check if the first symbol found in the local scope is the first symbol in the sym choice. If so, choose that symbol. Otherwise, give an ambiguous identifier error. The dependence on the local scope implies this will always give ambiguity errors for unpicked enum symchoices from generics and templates and macros from other scopes. We can change `not isAmbiguous(...) and foundSym == first` to `not (isAmbiguous(...) and foundSym == first)` to make it so they never give ambiguity errors, and always pick the first symbol in the symchoice. I can do this if this is preferred, but no code from CI seems affected.
* fixes #21887; Type conversion on overloaded enum field does not always call ↵ringabout2023-05-261-0/+8
| | | | | | | | | | | (#21908) * fixes #21887; Type conversion on overloaded enum field does not always call * remove comments * add a test case * restrict it to enums
* fixes #21863; Incorrect enum field access can cause internal error (#21886)ringabout2023-05-241-0/+28
| | | fixes 21863; Incorrect enum field access can cause internal error
* fixes #21280; Enum with int64.high() value crashes compiler (#21285)ringabout2023-05-061-0/+8
| | | | | | | | | | | | | | | * fixes #21280; Enum with int64.high() value crashes compiler * Update tests/enum/tenum.nim * Update tests/enum/tenum.nim * fixes tests * Update tests/enum/tenum.nim --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* megatest now checks refc too (#21341)ringabout2023-02-091-1/+2
| | | | | * megatest now checks refc too * fixes refc
* fixes #21207; reports redefinition error in the definition of enums (#21217)ringabout2023-01-031-0/+9
| | | | | * fixes #21207; reports redefinition in the enums * add a test
* closes #12589; add testcase (#20769)ringabout2022-11-061-2/+14
| | | | | | | * fixes #12589; add testcase * fixes i386 * i386
* closed ambiguous enum defaults to first overload (#20457)metagn2022-10-011-0/+5
| | | | | | | | | * closed ambiguous enum defaults to first overload * add warning * turn to hint * work around config
* overloadable enums no longer experimental (#20298)metagn2022-09-053-13/+12
| | | depends on #20126
* only allow enums to overload enums + extra test (#20126)metagn2022-09-031-0/+34
| | | mirror behavior without overloadableEnums
* add testcase for #16462 (#19692)flywind2022-04-073-0/+11
|
* fixes a regression caused by overloadable enums even though they're opt-in ↵Andreas Rumpf2021-10-072-0/+17
| | | | (#18970)
* fixes #18769 (#18790)Andreas Rumpf2021-09-031-1/+10
|
* add testcase for overloadable_enums (#18722)flywind2021-08-211-0/+29
| | | | | * add testcase for overloadable_enums * link
* implements overloadable enum values; WIP (#18470)Andreas Rumpf2021-07-281-0/+48
| | | | | * implements overloadable enum values * simpler code
* followup #17876: remove annoying enum name clashes in tests/enum/tenum.nim ↵Timothee Cour2021-06-171-12/+11
| | | | (#18291)
* type with same name in different scope now works (#17710)Timothee Cour2021-04-141-2/+3
| | | | * type with same name in different scope now works * fix tests/enum/tenum.nim which was wrong because it was affected by this bug
* fix #15145 (#15816)flywind2020-11-021-0/+11
|
* fix #15752 (#15754)cooldome2020-10-281-0/+9
|
* fix enumtostr crash for enum-range (#13035)Jasper Jenkins2020-01-051-0/+12
|
* add tests for recently closed issues (#10722)Miran2019-02-231-0/+9
|
* 32 bit fixes (#10608)Arne Döring2019-02-131-2/+2
|
* Deprecated pragma is now supported on enum fields (#10113)Neelesh Chandola2018-12-302-0/+32
| | | | | | * {.deprecated.} pragma is now supported for enum fields * Add tests * Simplify code
* require errormsg to be specified before file.Arne Döring2018-12-111-3/+1
|
* fixes #8671; show helpful msg (lookup symbol, eg iterator) on 'attempting to ↵Timothee Cour2018-10-141-1/+1
| | | | call undeclared routine' error (#8786)
* Merge tests into a larger file (part 2 of ∞) (#9335)Miran2018-10-139-139/+144
| | | | | | | | | | | | | | * merge controlflow tests * merge distinct tests * merge enum tests * merge fields tests * merge implicit tests * merge iter issues tests
* fixes #8066Araq2018-08-311-0/+19
|
* remove dead code elimination option (#7669)Jacek Sieka2018-04-231-1/+1
|
* Fixes #5062 (#5527); JS: holes in enumsSilvio2017-03-153-16/+39
|
* fixes #5148Araq2016-12-291-0/+7
|
* Added a test caseYuriy Glukhov2016-05-181-0/+6
|
* add tfile/tline assertions for template expansion file/lineAman Gupta2015-10-061-2/+2
|
* tests: Trim .nim files trailing whitespaceAdam Strzelecki2015-09-046-35/+35
| | | | via OSX: find . -name '*.nim' -exec sed -i '' -E 's/[[:space:]]+$//' {} +
* s/procedure/routine/ in tests.Dominik Picheta2015-06-051-1/+1
|
* Fixes #2584Dominik Picheta2015-06-041-1/+1
| | | | | Better compiler errors for accessing undeclared fields, calling undeclared procedures and procedure fields.
* fixes --gc:none regression; made some tests greenAraq2015-03-101-1/+1
|
* Fixes tenumitems test.Dominik Picheta2014-08-161-1/+1
|
* new tester; all tests categorizedAraq2014-01-139-0/+140