summary refs log tree commit diff stats
path: root/compiler/semexprs.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes #22354; Wrong C++ codegen for default parameter values in ORC (#22819)ringabout2023-10-131-2/+2
| | | | | | fixes #22354 It skips `nkHiddenAddr`. No need to hoist `var parameters` without side effects. Besides, it saves lots of temporary variables in ORC.
* fixes #22753; Nimsuggest segfault with invalid assignment to table (#22781)ringabout2023-10-021-1/+1
| | | | | | | | fixes #22753 ## Future work We should turn all the error nodes into nodes of a nkError kind, which could be a industrious task. But perhaps we can add a special treatment for error nodes to make the transition smooth.
* fixes #10542; suppresses varargs conversion warnings (#22757)ringabout2023-09-261-1/+2
| | | | fixes #10542 revives and close #20169
* make expressions opt in to symchoices (#22716)metagn2023-09-181-52/+47
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* Instantiates generics in the module that uses it (#22513)Juan M Gómez2023-09-091-1/+1
| | | | | | | | | | Attempts to move the generic instantiation to the module that uses it. This should decrease re-compilation times as the source module where the generic lives doesnt need to be recompiled --------- Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* resolve unambiguous enum symchoices from local scope, error on rest (#22606)metagn2023-09-031-1/+4
| | | | | | | | | | | | | | | | 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.
* unify explicit generic param semchecking in calls (#22618)metagn2023-09-011-4/+0
| | | fixes #9040
* Fix #22604: Make endsInNoReturn traverse the tree (#22612)SirOlaf2023-09-011-1/+0
| | | | | | | | | | | | | | | | | * 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/+4
| | | | | | | | | * type annotations for variable tuple unpacking, better error messages closes #17989, closes https://github.com/nim-lang/RFCs/issues/339 * update grammar * fix test
* `initCandidate` and friends now return values (#22570)ringabout2023-08-281-2/+1
| | | | | | | | | * `initCandidate` and friends now return values * fixes semexprs.nim * fixes semcall.nim * Update compiler/semcall.nim
* fixes a strictdef ten years long vintage bug, which counts the same thing ↵ringabout2023-08-241-0/+1
| | | | | twice (#22549) fixes a strictdef ten years long vintage bug
* round out tuple unpacking assignment, support underscores (#22537)metagn2023-08-241-1/+32
| | | | | | | | | | | | | | | * 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>
* cascade tyFromExpr in type conversions in generic bodies (#22499)metagn2023-08-171-5/+7
| | | fixes #22490, fixes #22491, adapts #22029 to type conversions
* unpublic the sons field of PType; the precursor to PType refactorings (#22446)ringabout2023-08-111-1/+1
| | | | | | | | | | | * unpublic the sons field of PType * tiny fixes * fixes an omittance * fixes IC * fixes
* `initNodeTable` and friends now return (#22444)ringabout2023-08-111-2/+1
|
* use strictdefs for compiler (#22365)ringabout2023-08-061-6/+15
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fix #20883 Unspecified generic on default value segfaults the compiler (#21172)Bung2023-08-041-0/+3
| | | | | | | | | * fix #20883 Unspecified generic on default value segfaults the compiler * fallback to isGeneric * change to closer error * Update t20883.nim
* Add experimental inferGenericTypes switch (#22317)SirOlaf2023-08-031-5/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Infer generic bindings * Simple test * Add t * Allow it to work for templates too * Fix some builds by putting bindings in a template * Fix builtins * Slightly more exotic seq test * Test value-based generics using array * Pass expectedType into buildBindings * Put buildBindings into a proc * Manual entry * Remove leftover ` * Improve language used in the manual * Experimental flag and fix basic constructors * Tiny commend cleanup * Move to experimental manual * Use 'kind' so tuples continue to fail like before * Explicitly disallow tuples * Table test and document tuples * Test type reduction * Disable inferGenericTypes check for CI tests * Remove tuple info in manual * Always reduce types. Testing CI * Fixes * Ignore tyGenericInst * Prevent binding already bound generic params * tyUncheckedArray * Few more types * Update manual and check for flag again * Update tests/generics/treturn_inference.nim * var candidate, remove flag check again for CI * Enable check once more --------- Co-authored-by: SirOlaf <> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Open scope for defer (#22315)SirOlaf2023-07-221-0/+2
| | | Co-authored-by: SirOlaf <>
* fixes #19101; zero initialization union casts (#22185)ringabout2023-06-291-5/+0
| | | | | | | * zero initialization union casts * cleans up and adds a test case for #19101 * uses nimZeroMem
* fix calls in generic bodies, delay typecheck when no overloads match (#22029)metagn2023-06-131-1/+4
| | | | | | | | | | | | | | | | | | | | | | | * sacrifice "tgenericshardcases" for working statics * legacy switch for CI, maybe experimental later * convert to experimental * apparently untyped needs the experimental switch * try special case call semcheck * try fix * fix compilation * final cleanup, not experimental, make `when` work * remove last needed use of untyped * fix unused warning in test * remove untyped feature
* Remove Deprecated Nimfix (#22062)Juan Carlos2023-06-101-3/+1
| | | | * Remove Deprecated Nimfix * Trailing whitespace cleanups
* properly disallow unresolved generic proc values (#22005)metagn2023-06-051-1/+13
| | | | | | | * properly disallow unresolved generic proc values * mirrors semoperand * shallow efTypeAllowed, add back special case
* fixes #21887; Type conversion on overloaded enum field does not always call ↵ringabout2023-05-261-0/+3
| | | | | | | | | | | (#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-1/+1
| | | fixes 21863; Incorrect enum field access can cause internal error
* fix #21251 Compiler SIGSEGV when using SharedTable (#21876)Bung2023-05-231-0/+2
| | | fix #21251
* fix #14254 (#21837)metagn2023-05-201-1/+3
| | | | | | | * fix #14254 * use temporary PR branch for neo * fix url
* adds an experimental `mm:atomicArc` switch (#21798)ringabout2023-05-081-1/+1
|
* cheap fix for #10853 + better tuple subscript error message (#21767)metagn2023-05-021-1/+4
| | | | | | | * cheap fix for #10853 * also better tuple subscript error message * weird
* handle quoted routine symbols and non symbols expressions as before (#21740)ringabout2023-04-281-2/+3
|
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-5/+5
| | | | | | | | | | | (#21667) * refactoring in preparation for better, simpler name mangling that works with IC flawlessly * use new disamb field * see if this makes tests green * make tests green again
* alias syntax fixes, improvements and tests (#21671)metagn2023-04-221-7/+13
| | | | | | | | | | | | | * alias syntax fixes, improvements and tests * even better, cannot use alias syntax with generics * more type tests, improve comment * fix again * consistent error message + make t5167_5 work * more comments, remove {.noalias.}
* warn on set types bigger than max size, default to 0..255 for int literals ↵metagn2023-04-171-14/+19
| | | | | | | | | | | | | | | | | | | (#21659) * test implicitly huge set types refs https://github.com/nim-lang/RFCs/issues/298 * oh my god * boot at least * don't error, fix remaining issues, no 2 len arrays * fix runnable example * test assuming 0..255 for int literal * test refactor, add changelog, test
* fixes #21674; `lent` can be used in the fields or the cast type as a ↵ringabout2023-04-181-1/+1
| | | | | | | | | parameter (#21684) * fixes #21674; `lent` can be used in the fields or the cast type as a parameter * add a test case * fix the test
* set module symbol type to None instead of nil for discard check (#21657)metagn2023-04-131-0/+6
| | | | | | | * set module symbol type to None instead of nil fixes #19225 * alright
* `proc` typeclass accounts for `iterator`, call conventions + `nil` fix + ↵metagn2023-04-111-0/+1
| | | | | | | | | | | | | 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
* tuple unpacking for vars as just sugar, allowing nesting (#21563)metagn2023-03-281-1/+1
| | | | | | | | | | | | | | | | | | | * tuple unpacking for vars as just sugar, allowing nesting * set temp symbol AST * hopeful fix some issues, add test for #19364 * always use temp for consts * document, fix small issue * fix manual indentation * actually fix manual * use helper proc * don't resem temp tuple assignment
* fixes #14255; Crash in compiler when using `system.any` by accident. (#21562)ringabout2023-03-231-1/+1
| | | fixes #14255; Crash in compiler when using system.any by accident.
* Use `analyseIfAddressTaken` logic for checking if address is taken in ↵Jake Leahy2023-03-201-9/+15
| | | | | | | | | | | | | | | | | | | converter (#21533) * Add a test case There are way more test cases (See all branches of analyseIfAddressTaken but this covers at least a second branch * Port analyseIfAddressTaken from semexprs to sigmatch This was done since we cannot import sem or semexprs (circular import) but we need the rest of the logic. In needs to be done here since the converter isn't semmed afterwards and so we can't just leave the process til later use the version from semexprs * Less hacky solution which has the checking be done in analyseIfAddressTakenInCall This was done instead of the recommendation on removing it since sfAddrTaken is used in places other than the backend * Remove weird whitespace * Still check nkHiddenAddr if we are checking a converter
* fixes quoted variables with typedesc types (#21493)ringabout2023-03-091-1/+1
|
* fixes #21377; fixes `@[]` and `{}` type inference as returns in generics ↵ringabout2023-03-061-1/+1
| | | | | | | | | | | | | (#21475) * fixes `@[]` type inference in generics * add issue links * fixes macros and iterators * refactor * add one more test
* fixes #21326; fixes #7375; fixes #11986; fixes #9607; rework quote do; ↵ringabout2023-03-021-4/+7
| | | | | | | | | | | | | `getAst` uses type info to annotate the type of quoted variables; no more type erasures for quoted variables (#21433) * fixes #21326; getAst uses type info to annotateType quoted variables * simplify logics; sem types first * fixes important packages * add testcases * tiny
* Implemented basic macro expand functionality (#20579)Ivan Yonchovski2023-01-271-1/+29
| | | | | | | | | | | | | | | | | | * Implemented level based macro expand functionality - it can handle single macro call or expand whole function/proc/etc and it - In addition, I have altered the parser to provide the endInfo for the node. The usefulness of the `endInfo` is not limited to the `expandMacro` functionality but also it is useful for `ideOutline` functionality and I have altered the ideOutline functionality to use `endInfo`. Note `endInfo` most of the time is lost during the AST transformation thus in `nimsuggest.nim` I am using freshly parsed tree to get the location information. * Make sure we stop expanding correctly * Test CI * Fix tv3_outline.nim
* fix #21109 (#21127)Bung2022-12-191-0/+2
|
* fix #20588 (#21104)Bung2022-12-151-0/+2
|
* fix #15836 proc arg return type auto unexpectly match proc with concr… ↵Bung2022-12-121-2/+4
| | | | | | | | | (#21065) * fix #15836 proc arg return type auto unexpectly match proc with concrete type * fix #16244 * add test case for #12869
* fix #16758 Nim crashes in fixAbstractType (#20855)Bung2022-12-111-0/+3
| | | | | | | | | * fix #16758 Nim crashes in fixAbstractType * Update compiler/semexprs.nim Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* Revert "fix #15836 proc arg return type auto unexpectly match proc with ↵ringabout2022-12-091-2/+2
| | | | | | | concr…" (#21057) Revert "fix #15836 proc arg return type auto unexpectly match proc with concr… (#21044)" This reverts commit 0cd9bdcf9f6802421e0d8e4c28fc732012af605e.
* fix #15836 proc arg return type auto unexpectly match proc with concr… ↵Bung2022-12-091-2/+2
| | | | | (#21044) fix #15836 proc arg return type auto unexpectly match proc with concrete type
* fixes #21027; cast expressions need a type (#21029)ringabout2022-12-061-0/+2
| | | | | | | * fixes #21027; cast expressions need a type * Apply suggestions from code review Thanks to @beef331