summary refs log tree commit diff stats
path: root/tests
Commit message (Collapse)AuthorAgeFilesLines
* 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) ```
* remove bad type inference behavior for enum identifiers (#23588)metagn2024-05-101-0/+22
| | | | | | | | | | | | | | | refs https://github.com/nim-lang/Nim/issues/23586#issuecomment-2102113750 In #20091 a bad kind of type inference was mistakenly left in where if an identifier `abc` had an expected type of an enum type `Enum`, and `Enum` had a member called `abc`, the identifier would change to be that enum member. This causes bugs where a local symbol can have the same name as an enum member but have a different value. I had assumed this behavior was removed since but it wasn't, and CI seems to pass having it removed. A separate PR needs to be made for the 2.0 branch because these lines were moved around during a refactoring in #23123 which is not in 2.0.
* adds Nim-related mimetypes back (#23589)ringabout2024-05-101-0/+5
| | | ref https://github.com/nim-lang/Nim/pull/23226
* fixes #23552; Invalid codegen when trying to mannualy delete distinct seq ↵ringabout2024-05-081-0/+8
| | | | | (#23558) fixes #23552
* Add Complex version of almostEqual function (#23549)Angel Ezquerra2024-05-081-0/+3
| | | | | | | | This adds a version of `almostEqual` (which was already available for floats) thata works with `Complex[SomeFloat]`. Proof that this is needed is that the first thing that the complex.nim runnable examples block did before this commit was define (an incomplete) `almostEqual` function that worked with complex values.
* fix semFinishOperands for bracket expressions [backport:2.0] (#23571)metagn2024-05-081-0/+24
| | | | | | | | | | | | | | | | fixes #23568, fixes #23310 In #23091 `semFinishOperands` was changed to not be called for `mArrGet` and `mArrPut`, presumably in preparation for #23188 (not sure why it was needed in #23091, maybe they got mixed together), since the compiler handles these later and needs the first argument to not be completely "typed" since brackets can serve as explicit generic instantiations in which case the first argument would have to be an unresolved generic proc (not accepted by `finishOperand`). In this PR we just make it so `mArrGet` and `mArrPut` specifically skip calling `finishOperand` on the first argument. This way the generic arguments in the explicit instantiation get typed, but not the unresolved generic proc.
* rework `wasMoved`, `move` on the JS backend (#23577)ringabout2024-05-081-11/+23
| | | | | `reset`, `wasMoved` and `move` doesn't support primitive types, which generate `null` for these types. It is now produce `x = default(...)` in the backend. Ideally it should be done by ast2ir in the future
* Skips generic owner when mangling instances (#23563)Juan M Gómez2024-05-071-4/+5
|
* fixes #23556; typeinfo.extendSeq generates random values in ORC (#23557)ringabout2024-05-031-0/+17
| | | | | fixes #23556 It should somehow handle default fields in the future
* fixes #23419; internal error with void in generic array instantiation (#23550)ringabout2024-05-011-0/+5
| | | | | | | | | fixes #23419 `void` is only supported as fields of objects/tuples. It shouldn't allow void in the array. I didn't merge it with taField because that flag is also used for tyLent, which is allowed in the fields of other types.
* fixes #23321; Error: internal error: openArrayLoc: ref array[0..0, int] (#23548)ringabout2024-04-291-0/+35
| | | | | | | | fixes #23321 In the function `mapType`, ptrs (tyPtr, tyVar, tyLent, tyRef) are mapped into ctPtrToArray, the dereference of which is skipped in the `genref`. We need to skip these ptrs in the function `genOpenArraySlice`.
* fixes #23531; fixes invalid meta type accepted in the object fields (#23532)ringabout2024-04-261-0/+61
| | | | | fixes #23531 fixes #19546 fixes #6982
* fixes #23536; Stack trace with wrong line number when the proc called inside ↵ringabout2024-04-261-0/+26
| | | | | for loop (#23540) fixes #23536
* fixes #23522; fixes pre-existing wrong type for iter in `liftIterSym` (#23538)ringabout2024-04-261-0/+3
| | | fixes #23522
* adds another fix for concept in JS (#23535)ringabout2024-04-241-4/+12
| | | ref https://github.com/nim-lang/Nim/issues/9550
* fixes #23524; global variables cannot be analysed when injecting `move` (#23529)ringabout2024-04-242-17/+33
| | | | | | | | | | | | fixes #23524 ```nim proc isAnalysableFieldAccess*(orig: PNode; owner: PSym): bool = ... result = n.kind == nkSym and n.sym.owner == owner and {sfGlobal, sfThread, sfCursor} * n.sym.flags == {} and (n.sym.kind != skParam or isSinkParam(n.sym)) ``` In `isAnalysableFieldAccess`, globals, cursors are already rejected
* Fix std/base64.decode out of bounds read (#23526)bptato2024-04-221-0/+2
| | | | inputLen may end up as 0 in the loop if the input string only includes trailing characters. e.g. without the patch, decode(" ") would panic.
* Fix duplicated member declarations in structs for C++ backend (#23512)HexSegfaultCat2024-04-181-0/+27
| | | | | | | | | | | | | | | When forward declaration is used with pragmas `virtual` or `member`, the declaration in struct is added twice. It happens because of missing check for `sfWasForwarded` pragma. Current compiler generates the following C++ code: ```cpp struct tyObject_Foo__fFO9b6HU7kRnKB9aJA1RApKw { N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); N_LIB_PRIVATE N_NOCONV(void, abc)(NI x_p1); N_LIB_PRIVATE N_NOCONV(virtual void, def)(NI y_p1); }; ```
* workaround #23435; real fix pending #23279 (#23436)ringabout2024-04-181-0/+12
| | | | | | | workaround #23435 related to https://github.com/nim-lang/Nim/issues/22852 see also #23279
* fixes #4695; closure iterators support for JS backend (#23493)ringabout2024-04-181-4/+1
| | | | | | | | | | | | | | | | | | | | | | | fixes #4695 ref https://github.com/nim-lang/Nim/pull/15818 Since `nkState` is only for the main loop state labels and `nkGotoState` is used only for dispatching the `:state` (since https://github.com/nim-lang/Nim/pull/7770), it's feasible to rewrite the loop body into a single case-based dispatcher, which enables support for JS, VM backend. `nkState` Node is replaced by a label and Node pair and `nkGotoState` is only used for intermediary processing. Backends only need to implement `nkBreakState` and `closureIterSetupExc` to support closure iterators. pending https://github.com/nim-lang/Nim/pull/23484 <del> I also observed some performance boost for C backend in the release mode (not in the danger mode though, I suppose the old implementation is optimized into computed goto in the danger mode) </del> allPathsAsgnResult???
* fixes #23505; fixes injectdestructors errors on transformed addr (deref) ↵ringabout2024-04-181-0/+13
| | | | | refs (#23507) fixes #23505
* fixes #23499; don't skip `addr` when constructing `bracketExpr` (#23503)ringabout2024-04-151-0/+10
| | | | | | | | | | | fixes #23499 In the https://github.com/nim-lang/Nim/commit/8990626ca9715a3687b28331aee4ccf242997aa2 the effect of `skipAddr` changed to skip `nkAddr` and `nkHiddenAddr`. Some old code was not adapted. In the https://github.com/nim-lang/Nim/pull/23477, the magic `addr` function was handled in the semantic analysis phase, which causes it be skipped incorrectly
* [JS backend] improve `discard` statement; ridding of the awkward special ↵ringabout2024-04-131-1/+1
| | | | | | | | | | variable `_` (#23498) According to https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/Expression_statement, some expression statements need parentheses to make it unambiguous. `_` introduced in the https://github.com/nim-lang/Nim/pull/15789 is unnecessary. We can get rid of it by adding parentheses so that object literals are not ambiguous with block statements.
* fixes #4299 #12492 #10849; lambda lifting for JS backend (#23484)ringabout2024-04-114-7/+51
| | | | | | | | fixes #4299 fixes #12492 fixes #10849 It binds `function` with `env`: `function.bind(:env)` to ease codegen for now
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-103-1/+24
|
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-092-0/+62
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23326 In a routine declaration node in a template, if the routine is marked as `gensym`, the compiler adds it as a new symbol to a preliminary scope of the template. If it's not marked as gensym, then it searches the preliminary scope of the template for the name of the routine, then when it matches a template parameter or a gensym identifier, the compiler replaces the name node with a symbol node of the found symbol. This makes sense for the template parameter since it has to be replaced later, but not really for the gensym identifier, as it doesn't allow us to inject a routine with the same name as an identifier previously declared as gensym (the problem in #23326 is when this is in another `when` branch). However this is the only channel to reuse a gensym symbol in a declaration, so maybe removing it has side effects. For example if we have: ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) {.gensym.} = discard ``` it will not behave the same as ```nim proc foo(x: int) {.gensym.} = discard proc foo(x: float) = discard ``` behaved previously, which maybe allowed overloading over the gensym'd symbols. A note to the "undeclared identifier" error message has also been added for a potential error code that implicitly depended on the old behavior might give, namely ``undeclared identifier: 'abc`gensym123'``, which happens when in a template an identifier is first declared gensym in code that doesn't compile, then as a routine which injects by default, then the identifier is used.
* Update encodings.nim, fix `open` with bad arg raising no `EncodingError` ↵lit2024-04-061-0/+4
| | | | | | (#23481) On POSIX, `std/encodings` uses iconv, and `iconv_open` returns `(iconv_t) -1` on failure, not `NULL`
* fixes JS tests (#23479)ringabout2024-04-051-1/+1
|
* fixes #16771; lower `swap` for JS backend (#23473)ringabout2024-04-031-0/+19
| | | | | | | | | | | | fixes #16771 follow up https://github.com/nim-lang/Nim/pull/16536 Ideally it should be handled in the IR part in the future I have also checked the double evaluation of `swap` in the JS runtime https://github.com/nim-lang/Nim/issues/16779, that might be solved by a copy flag or something. Well, it should be best solved in the IR so that it doesn't bother backends anymore.
* fixes testament targets field (#23472)ringabout2024-04-033-3/+3
|
* fixes #9550; Concept related crash only when compiling to JS (#23470)ringabout2024-04-021-0/+11
| | | fixes #9550
* adds ccMember CC fixes #23434 (#23457)Juan M Gómez2024-03-291-0/+17
|
* fixes #23422; card regression (#23437)ringabout2024-03-281-0/+38
| | | | | | | | | fixes #23422 ref https://github.com/nim-lang/Nim/issues/20997 https://github.com/nim-lang/Nim/pull/21165 The function `cardSet` is used for large sets that are stored in the form of arrays. It shouldn't be passed as a pointer
* [Cpp] Fixes an issue when mixing hooks and calls (#23428)Juan M Gómez2024-03-211-1/+14
|
* propagate efWantStmt in semWhen (#23400)metagn2024-03-141-0/+7
| | | | | | | | fixes #23399 The new case introduced in #21657 is triggered by `efWantStmt` but the `when` statement doesn't normally propagate this flag, so propagate it when the `semCheck` param in `semWhen` is true which happens when the `when` statement is `efWhenStmt` anyway.
* [C++] Allow `member` to define static funcs (#23387)Juan M Gómez2024-03-111-1/+12
|
* Update tests/js/tos.nim, make isAbsolute tested on nodejs under Windows. ↵lit2024-03-091-6/+4
| | | | | | | | (#23377) Windows's nodejs `isAbsolute` issue has been resolved by [this PR](https://github.com/nim-lang/Nim/pull/23365). So we can improve the coverage for Windows.
* fixes #22284; fixes #22282; don't override original parameters of inferred ↵ringabout2024-03-091-0/+25
| | | | | | | | | | | | | | | | | lambdas (#23368) fixes #22284 fixes #22282 ``` Error: j(uRef, proc (config: F; sources: auto) {.raises: [].} = discard ) can raise an unlisted exception: Exception ``` The problem is that `n.typ.n` contains the effectList which shouldn't appear in the parameter of a function defintion. We could not simply use `n.typ.n` as `n[paramsPos]`. The effect lists should be stripped away anyway.
* fixes #23378; fixes js abs negative int64 (#23379)ringabout2024-03-091-0/+8
| | | fixes #23378
* closes #22846; adds a test case (#23374)ringabout2024-03-081-0/+9
| | | closes #22846
* closes #15751; adds a test case (#23372)ringabout2024-03-061-0/+11
| | | closes #15751
* fixes #12703; nim cpp rejects valid code would lose const qualifier for ↵ringabout2024-03-051-0/+14
| | | | | | cstring to string via cstrToNimstr (#23371) fixes #12703 ref #19588
* closes #10219; adds a test case (#23370)ringabout2024-03-051-0/+20
| | | closes #10219
* Dont mangle when targeting cpp (#23335)Juan M Gómez2024-03-031-1/+1
| | | | Unfortunately we cant trick the debugger when targeting C++ so this one also needs to wait for our own debugger adapter.
* fixes sink regression for ORC; ref #23354 (#23359)ringabout2024-03-031-0/+16
| | | | | | | | | ref #23354 The new move analyzer requires types that have the tfAsgn flag (otherwise `lastRead` will return true); tfAsgn is included when the destructor is not trival. But it should consider the assignement for objects in this case because objects might have a trival destructors but it's the assignement that matters when it is passed to sink parameters.
* fixes #13481; fixes #22708; disable using union objects in VM (#23362)ringabout2024-03-031-8/+0
| | | | | | fixes #13481; fixes #22708 Otherwise it gives implicit results or bad codegen
* strformat: detect format string errors at compile-time (#23356)Jacek Sieka2024-03-031-1/+14
| | | | | | | | | | | | This also prevents unwanted `raises: [ValueError]` effects from bubbling up from correct format strings which makes `fmt` broadly unusable with `raises`. The old runtime-based `formatValue` overloads are kept for backwards-compatibility, should anyone be using runtime format strings. --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #23306 nim cpp -r invalid code generation regression with closure ↵Juan M Gómez2024-02-261-0/+12
| | | | iterators and try/catch-like constructions (#23317)
* fixes #22723; skips tyUserTypeClasses in injectdestructors (#23341)ringabout2024-02-241-0/+24
| | | fixes #22723