summary refs log tree commit diff stats
path: root/compiler/semstmts.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes semi-regression; discard check now skips `nkHiddenSubConv` (#23840)ringabout2024-07-161-1/+1
| | | | | follow up https://github.com/nim-lang/Nim/pull/23681 ref https://forum.nim-lang.org/t/11987
* fixes regression; block can have arbitrary exit points; too hard for a ↵ringabout2024-07-161-5/+6
| | | | | | | | simple analysis (#23839) follow up https://github.com/nim-lang/Nim/pull/23681 ref https://forum.nim-lang.org/t/11987 ref https://github.com/nim-lang/Nim/issues/23836#issuecomment-2227267251
* [minor] fixes wrong error messages (#23841)ringabout2024-07-161-1/+1
|
* fixes #3011; handles meta fields defined in the ref object (#23818)ringabout2024-07-111-2/+7
| | | | | | | | | | | | | | | | | | | | | | | fixes #3011 In https://github.com/nim-lang/Nim/pull/23532, meta fields that defined in the object are handled. In this PR, RefObjectTy is handled as well: ```nim type Type = ref object context: ref object ``` Ref alias won't trigger mata fields checking so there won't have cascaded errors on `TypeBase`. ```nim type TypeBase = object context: ref object Type = ref TypeBase context: ref object ```
* fixes #23775; injectdestructors now handles discardable statements (#23780)ringabout2024-07-021-0/+1
| | | fixes #23775
* [backport] fixes #23711; C code contains backtick`gensym (#23716)ringabout2024-06-191-1/+1
| | | fixes #23711
* fix noreturn/implicit discard check logic (#23681)metagn2024-06-051-13/+132
| | | | | | | | | | | | | | | | | | | | | | | | | | fixes #10440, fixes #13871, fixes #14665, fixes #19672, fixes #23677 The false positive in #23677 was caused by behavior in `implicitlyDiscardable` where only the last node of `if`/`case`/`try` etc expressions were considered, as in the final node of the final branch (in this case `else`). To fix this we use the same iteration in `implicitlyDiscardable` that we use in `endsInNoReturn`, with the difference that for an `if`/`case`/`try` statement to be implicitly discardable, all of its branches must be implicitly discardable. `noreturn` calls are also considered implicitly discardable for this reason, otherwise stuff like `if true: discardableCall() else: error()` doesn't compile. However `endsInNoReturn` also had bugs, one where `finally` was considered in noreturn checking when it shouldn't, another where only `nkIfStmt` was checked and not `nkIfExpr`, and the node given for the error message was bad. So `endsInNoReturn` now skips over `skipForDiscardable` which no longer contains `nkIfStmt`/`nkCaseStmt`/`nkTryStmt`, stores the first encountered returning node in a var parameter for the error message, and handles `finally` and `nkIfExpr`. Fixing #23677 already broke a line in `syncio` so some package code might be affected.
* fixes #23531; fixes invalid meta type accepted in the object fields (#23532)ringabout2024-04-261-9/+17
| | | | | fixes #23531 fixes #19546 fixes #6982
* Fix duplicated member declarations in structs for C++ backend (#23512)HexSegfaultCat2024-04-181-1/+1
| | | | | | | | | | | | | | | 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); }; ```
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-2/+2
|
* refactoring: no inheritance for PType/PSym (#23403)Andreas Rumpf2024-03-141-1/+1
|
* fixes #22284; fixes #22282; don't override original parameters of inferred ↵ringabout2024-03-091-1/+0
| | | | | | | | | | | | | | | | | 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 refc with non-var destructor; cancel warnings (#23156)ringabout2024-02-131-3/+13
| | | fixes https://forum.nim-lang.org/t/10807
* fixes #18104; tranform one liner var decl before templates expansion (#23294)ringabout2024-02-131-0/+18
| | | fixes #18104
* fixes #12334; keeps `nkHiddenStdConv` for cstring conversions (#23216)ringabout2024-01-181-0/+2
| | | | | | fixes #12334 `nkHiddenStdConv` shouldn't be removed if the sources aren't literals, viz. constant symbols.
* fixes #23180; fixes #19805; prohibits invalid tuple unpacking code in for ↵ringabout2024-01-131-1/+4
| | | | | | loop (#23185) fixes #23180 fixes #19805
* retain postfix node in type section typed AST, with docgen fix (#23101)metagn2023-12-231-3/+19
| | | | | | Continued from #23096 which was reverted due to breaking a package and failing docgen tests. Docgen should now work, but ~~a PR is still pending for the package: https://github.com/SciNim/Unchained/pull/45~~ has been merged
* Revert "retain postfix node in type section typed AST" (#23098)metagn2023-12-191-19/+3
| | | Reverts nim-lang/Nim#23096
* retain postfix node in type section typed AST (#23096)metagn2023-12-181-3/+19
| | | fixes #22933
* Mark `macros.error` as `.noreturn.` (#23081)Jake Leahy2023-12-171-0/+5
| | | | | | | | | | | | | | | Closes #14329 Marks `macros.error` as `.noreturn` so that it can be used in expressions. This also fixes the issue that occurred in #19659 where a stmt that could be an expression (Due to having `discardable` procs at the end of other branches) would believe a `noreturn` proc is returning the same type e.g. ```nim proc bar(): int {.discardable.} = discard if true: bar() else: quit(0) # Says that quit is of type `int` and needs to be used/discarded except it actually has no return type ```
* type graph refactor; part 3 (#23064)Andreas Rumpf2023-12-141-6/+6
|
* type refactoring: part 2 (#23059)Andreas Rumpf2023-12-131-25/+29
|
* Types: Refactorings; step 1 (#23055)Andreas Rumpf2023-12-121-64/+64
|
* Only suggest symbols that could be pragmas when typing a pragma (#23040)Jake Leahy2023-12-071-0/+4
| | | | | | Currently pragmas just fall through to `suggestSentinel` and show everything which isn't very useful. Now it filters for symbols that could be pragmas (templates with `{.pragma.}`, macros, user pragmas) and only shows them
* Fix nimsuggest `def` being different on proc definition/use (#23025)Jake Leahy2023-12-041-2/+12
| | | | | | | | | | | | | | | | | | Currently the documentation isn't shown when running `def` on the definition of a proc (Which works for things like variables). `gcsafe`/`noSideEffects` status also isn't showing up when running `def` on the definition Images of current behavior. After PR both look like "Usage" **Definition** ![image](https://github.com/nim-lang/Nim/assets/19339842/bf75ff0b-9a96-49e5-bf8a-d2c503efa784) **Usage** ![image](https://github.com/nim-lang/Nim/assets/19339842/15ea3ebf-64e1-48f5-9233-22605183825f) Issue was the symbol getting passed too early to nimsuggest so it didn't have all that info, now gets passed once proc is fully semmed
* Fix endsInNoReturn for case statements (#23009)SirOlaf2023-11-301-8/+2
| | | | | | | | | While looking at the CI I noticed that there's a couple false positives for `case` statements that cannot be checked for exhaustiveness since my changes, this should resolve them. --------- Co-authored-by: SirOlaf <>
* IC: progress and refactorings (#22961)Andreas Rumpf2023-11-201-5/+5
|
* Inlay hints for types of consts (#22916)Nikolay Nikolov2023-11-071-0/+4
| | | This adds inlay hint support for the types of consts.
* Inlay hints support (#22896)Nikolay Nikolov2023-11-041-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | This adds inlay hints support to nimsuggest. It adds a new command to nimsuggest, called 'inlayHints'. Currently, it provides type information to 'var' and 'let' variables. In the future, inlay hints can also be added for 'const' and for function parameters. The protocol also reserves space for a tooltip field, which is not used, yet, but support for it can be added in the future, without further changing the protocol. The change includes refactoring to allow the 'inlayHints' command to return a completely different structure, compared to the other nimsuggest commands. This will allow other future commands to have custom return types as well. All the previous commands return the same structure as before, so perfect backwards compatibility is maintained. To use this feature, an update to the nim language server, as well as the VS code extension is needed. Related PRs: nimlangserver: https://github.com/nim-lang/langserver/pull/53 VS code extension: https://github.com/saem/vscode-nim/pull/134 --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* suppress incorrect var T destructor warnings for newFinalizer in stdlib (#22810)ringabout2023-10-111-2/+2
| | | | | | | | | | | | in `std/nre` ```nim proc initRegex(pattern: string, flags: int, study = true): Regex = new(result, destroyRegex) ``` gives incorrect warnings like ``` C:\Users\blue\Documents\Nim\lib\impure\nre.nim(252, 6) Error: A custom '=destroy' hook which takes a 'var T' parameter is deprecated; it should take a 'T' parameter [Deprecated ```
* fixes compiler crash by preventing exportc on generics (#22731)Juan M Gómez2023-09-201-3/+6
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* `constructor` now uses `result` instead of `this` (#22724)Juan M Gómez2023-09-191-28/+8
|
* prevents declaring a constructor without importcpp fixes #22712 (#22715)Juan M Gómez2023-09-181-2/+7
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* implements RFC: [C++] Constructors as default initializers (#22694)Juan M Gómez2023-09-141-29/+50
| | | Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fixes #22669 constructor pragma doesnt init Nim default fields (#22670)Juan M Gómez2023-09-101-0/+2
| | | | | | | fixes #22669 constructor pragma doesnt init Nim default fields --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* don't update const symbol on const section re-sems (#22609)metagn2023-09-011-5/+10
| | | fixes #19849
* Fix #22604: Make endsInNoReturn traverse the tree (#22612)SirOlaf2023-09-011-3/+1
| | | | | | | | | | | | | | | | | * Rewrite endsInNoReturn * Handle `try` stmt again and add tests * Fix unreachable code warning * Remove unreachable code in semexprs again * Check `it.len` before skip * Move import of assertions --------- Co-authored-by: SirOlaf <>
* type annotations for variable tuple unpacking, better error messages (#22611)metagn2023-09-011-2/+8
| | | | | | | | | * type annotations for variable tuple unpacking, better error messages closes #17989, closes https://github.com/nim-lang/RFCs/issues/339 * update grammar * fix test
* round out tuple unpacking assignment, support underscores (#22537)metagn2023-08-241-7/+10
| | | | | | | | | | | | | | | * round out tuple unpacking assignment, support underscores fixes #18710 * fix test messages * use discard instead of continue Co-authored-by: Andreas Rumpf <rumpf_a@web.de> --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* unpublic the sons field of PType; the precursor to PType refactorings (#22446)ringabout2023-08-111-7/+7
| | | | | | | | | | | * unpublic the sons field of PType * tiny fixes * fixes an omittance * fixes IC * fixes
* fix #19304 Borrowing std/times.format causes Error: illformed AST (#20659)Bung2023-08-101-12/+21
| | | | | | | | | * fix #19304 Borrowing std/times.format causes Error: illformed AST * follow suggestions * mitigate for #4121 * improve error message
* [C++] Member pragma RFC (https://github.com/nim-lang/RFCs/issues/530) (#22272)Juan M Gómez2023-08-071-7/+8
| | | | | | | | | | * [C++] Member pragma RFC #530 rebase devel * changes the test so `echo` is not used before Nim is init * rebase devel * fixes Error: use explicit initialization of X for clarity [Uninit]
* use strictdefs for compiler (#22365)ringabout2023-08-061-6/+25
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* Check try block for endsInNoReturn (#22314)SirOlaf2023-07-221-2/+3
| | | Co-authored-by: SirOlaf <>
* fix new type inference for `noreturn` [backport] (#22182)metagn2023-06-281-7/+14
| | | | | fixes #22180 Backported since apparently the new type inference was backported
* allow destructors to accept non var parameters; deprecate `proc =destroy(x: ↵ringabout2023-06-211-1/+6
| | | | | | | | | | var T)` (#22130) * make destructors accept non var parameters * define nimAllowNonVarDestructor * add a test case and a changelog * update documentation and error messages * deprecate destructors taking 'var T'
* overhaul the error messages of `=dup` (#22129)ringabout2023-06-201-6/+41
|
* Allows for arbitrary ordering of inheritance in type section #6259 (#22070)Juan M Gómez2023-06-151-2/+3
| | | | | | | | | | | | | * Allows for arbitrary ordering of inheritance in type section #6259 * prevents ilegal recursion * fixes ilegal recursion. Test passes with a better message * Apply suggestions from code review --------- Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* make borrow `.` work with aliases if not overriden (#22072)metagn2023-06-111-3/+8
|
* Remove Deprecated Nimfix (#22062)Juan Carlos2023-06-101-13/+7
| | | | * Remove Deprecated Nimfix * Trailing whitespace cleanups