summary refs log tree commit diff stats
path: root/compiler/lookups.nim
Commit message (Collapse)AuthorAgeFilesLines
* fixes addr/hiddenAddr in strictdefs (#23477)ringabout2024-04-101-8/+8
|
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-091-1/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* ambiguous identifier resolution (#23123)metagn2024-01-011-28/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`
* Param match relax (#23033)Ryan McConnell2023-12-151-0/+12
| | | | | | | | | | | #23032 --------- Co-authored-by: Nikolay Nikolov <nickysn@gmail.com> Co-authored-by: Pylgos <43234674+Pylgos@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: ringabout <43030857+ringabout@users.noreply.github.com> Co-authored-by: Jason Beetham <beefers331@gmail.com>
* prepare for the enforcement of `std` prefix (#22873)ringabout2023-10-291-3/+5
| | | follow up https://github.com/nim-lang/Nim/pull/22851
* fixes branches interacting with break, raise etc. in strictdefs (#22627)ringabout2023-09-041-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ```nim {.experimental: "strictdefs".} type Test = object id: int proc test(): Test = if true: return Test() else: return echo test() ``` I will tackle https://github.com/nim-lang/Nim/issues/16735 and #21615 in the following PR. The old code just premises that in branches ended with returns, raise statements etc. , all variables including the result variable are initialized for that branch. It's true for noreturn statements. But it is false for the result variable in a branch tailing with a return statement, in which the result variable is not initialized. The solution is not perfect for usages below branch statements with the result variable uninitialized, but it should suffice for now, which gives a proper warning. It also fixes ```nim {.experimental: "strictdefs".} type Test = object id: int proc foo {.noreturn.} = discard proc test9(x: bool): Test = if x: foo() else: foo() ``` which gives a warning, but shouldn't
* resolve unambiguous enum symchoices from local scope, error on rest (#22606)metagn2023-09-031-0/+35
| | | | | | | | | | | | | | | | 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.
* `initNodeTable` and friends now return (#22444)ringabout2023-08-111-2/+2
|
* use strictdefs for compiler (#22365)ringabout2023-08-061-4/+16
| | | | | | | | | | | | | | | * wip; use strictdefs for compiler * checkpoint * complete the chores * more fixes * first phase cleanup * Update compiler/bitsets.nim * cleanup
* fixes #21231; template with module as parameter elides usage/checking of ↵ringabout2023-06-211-0/+3
| | | | | | | module name specifier (#22109) * fixes #21231; template with module as parameter elides usage/checking of module name specifier * add a test case
* Remove Deprecated Nimfix (#22062)Juan Carlos2023-06-101-9/+2
| | | | * Remove Deprecated Nimfix * Trailing whitespace cleanups
* make deprecated statement a no-op (#21836)metagn2023-05-121-36/+25
|
* underscore as special word (#21766)metagn2023-05-021-3/+3
| | | | | * underscore as special word * fix really hard to notice error
* refactoring in preparation for better, simpler name mangling that wor… ↵Andreas Rumpf2023-04-241-1/+1
| | | | | | | | | | | (#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
* implements #21620: allowing to import multiple modules with shared names ↵Juan M Gómez2023-04-211-8/+13
| | | | (#21628)
* tweak spellsuggest; three counts for equal distances candidates by default ↵ringabout2023-04-211-6/+3
| | | | | | | (#21700) * tweak spellsuggest; three counts for equal distances candidates * only suggest typos when length > 3
* document general use of `_`, error message, fixes (#21584)metagn2023-03-301-11/+16
| | | | | | | | | | | | * document general use of `_`, error message, fixes fixes #20687, fixes #21435 Documentation and changelog updated to clarify new universal behavior of `_`. Also new error message for attempting to use `_`, new tests, and fixes with overloadable symbols and implicit generics. * add test for #21435
* fixes #21496; Ambiguous calls compiles when module name are equal (#21500)ringabout2023-03-121-1/+2
| | | | | * fixes #21496; Ambiguous calls compiles when module name are equal * add a test case
* fixes #21263; consider all candidates for concept matches (#21265)ringabout2023-01-171-0/+17
|
* underscores for routine parameters (#21192)metagn2023-01-081-0/+1
| | | | | | | | | * underscores for routine parameters fixes #13443, fixes #13804, refs #21121 * add changelog + more tests * support generics and ensure inferred lambdas work
* Don't repeat suggestions for same symbol (#21140)Jake Leahy2022-12-221-5/+20
| | | | | | | | | | * Track seen module graphs so symbols from the same module aren't repeated Add test case * Track symbols instead of modules * Don't show duplicate symbols in spell checker Removes the declared location from the message. Since we don't show duplicates anymore it would be a bit misleading if we only show the location for the first declaration of the symbol
* fix #15836 proc arg return type auto unexpectly match proc with concr… ↵Bung2022-12-121-1/+1
| | | | | | | | | (#21065) * fix #15836 proc arg return type auto unexpectly match proc with concrete type * fix #16244 * add test case for #12869
* Revert "fix #15836 proc arg return type auto unexpectly match proc with ↵ringabout2022-12-091-1/+1
| | | | | | | 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-1/+1
| | | | | (#21044) fix #15836 proc arg return type auto unexpectly match proc with concrete type
* [backport] Handle nkOpenSymChoice for nkAccQuoted in considerQuotedIdent ↵SirOlaf2022-10-181-0/+5
| | | | | | | | | | | | (#20578) * Handle nkOpenSymChoice for nkAccQuoted in considerQuotedIdent * Add test * Update compiler/lookups.nim Co-authored-by: SirOlaf <a> Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
* fix #18886 crash on ambiguous proc cast (#20472)Bung2022-10-101-2/+9
| | | | | * fix #18886 crash on ambiguous proc cast * follow suggestion
* overloadable enums no longer experimental (#20298)metagn2022-09-051-2/+0
| | | depends on #20126
* move assertions out of system (#19599)flywind2022-03-231-0/+4
|
* [minor]break loops after a candidate is added to seqs (#18770)flywind2021-08-311-7/+9
| | | | | | | | | * [minor]break loops when added * Update compiler/lookups.nim Co-authored-by: Clyybber <darkmine956@gmail.com> Co-authored-by: Clyybber <darkmine956@gmail.com>
* [minor] break loops if it is ambiguous (#18745)flywind2021-08-271-6/+7
| | | | | | | | | * [minor] break loops if it is ambiguous * Update compiler/lookups.nim Co-authored-by: Timothee Cour <timothee.cour2@gmail.com> Co-authored-by: Timothee Cour <timothee.cour2@gmail.com>
* implements overloadable enum values; WIP (#18470)Andreas Rumpf2021-07-281-2/+5
| | | | | * implements overloadable enum values * simpler code
* Cleanup lookups.nim again.. (#18379)Clyybber2021-06-281-4/+4
|
* followup #18362: make `UnusedImport` work robustly (#18366)Timothee Cour2021-06-271-4/+8
| | | | * warnDuplicateModuleImport => hintDuplicateModuleImport * improve DuplicateModuleImport msg, add test
* even lighter version of #17938: fix most issues with UnusedImport, ↵Timothee Cour2021-06-261-7/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | XDeclaredButNotUsed, etc; fix #17511, #17510, #14246 (without realModule) (#18362) * {.used: symbol} * add tests * fix tests with --import * --import works without giving spurious unused warnings * new warning warnDuplicateModuleImport for `import foo; import foo` * fix test, add resolveModuleAlias, use proper line info for module aliases * fix spurious warnings * fix deprecation msg for deprecated modules even with `import foo as bar` * disable a test for i386 pending sorting XDeclaredButNotUsed errors * UnusedImport now works with re-exported symbols * fix typo [skip ci] * ic support * add genPNode to allow writing PNode-based compiler code similarly to `genAst` * fix DuplicateModuleImport warning * adjust test * fixup * fixup * fixup * fix after rebase * fix for IC * keep the proc inline, move the const out * [skip ci] fix changelog * experiment: remove calls to resolveModuleAlias * followup * fixup * fix tests/modules/tselfimport.nim * workaround tests/deprecated/tmodule1.nim * fix properly * simplify
* fix #18332: XDeclaredButNotUsed hints now in deterministic order (#18336)Timothee Cour2021-06-241-4/+6
|
* Don't report unused hints for consumed AST (#18270)Clyybber2021-06-161-1/+3
| | | | | | | | | * Fix #18203 * Add testcase * Fix testcase * Fix test
* add test case for pure enum redefinition error within enum (fixed in recent ↵Timothee Cour2021-06-151-0/+2
| | | | | | | | | | | | | PR) (#18266) * add test case for pure enum redefinition error within enum (fixed in recent PR) * remove code duplication * Revert "remove code duplication" (would require bootstrap >= 1.4) This reverts commit 3f793874c231f847ef015e37a5fd6851f85d9675. * fixup
* Small scope refactoring (#18263)Clyybber2021-06-141-19/+17
| | | | | | | * Small scope refactoring * Add test for #10251 * Add inline where appropriate
* fixes #18235 - proc annotation type macro sym leak (#18249)Saem Ghani2021-06-141-5/+22
| | | | | | | | | | | | | | | | | | | | | * fixes #18235 - proc annotation type macro sym leak - also fixed a typo - proc annotations guard symbol exports with shadow scopes - symbol handling is shadow scope aware * test for exporting an existing unexported sym this one is for my homie alaviss. * Special handling not needed in semProcAnnotation * Testcasing * [skip ci] clean-up and add some more comments * [skip ci] rm trailing whitespace Co-authored-by: Clyybber <darkmine956@gmail.com>
* add astmsgs; add `declared in` msg for usage lint errors (#17961)Timothee Cour2021-05-081-1/+1
| | | | | | | | | * add astmsgs; add `declared in` msg for usage lint errors * fix test * fix tests/tools/tlinter.nim * std prefix
* CIs: attempt to use csources_v1 (#16282)Andreas Rumpf2021-04-211-1/+1
| | | | | | | | * CIs: attempt to use csources_v1 * also updated the BSDs * also updated azure pipelines * std modules should not itself use the 'std/' import dir... * compiler has to be careful with std/ for v1 booting
* `import foo {.all.}` reboot (#17706)Timothee Cour2021-04-161-3/+9
|
* adjust spellSuggestSecretSauce logic to avoid too many matches for small ↵Timothee Cour2021-03-181-2/+8
| | | | symbols (#17410)
* semLambda removed, semProcAux reworked (#17379)Saem Ghani2021-03-171-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * simplified proc-like name ident to symbol code * wip - reworking generic param sem * wip - closer to removing nkEmpty generic params * it's hacky but tests pass * slowly tweaking semProcAux to take on semLambda * fix pragma superset check proto vs current * Set the symbol owner earlier * partial progress reworking proto found bug where default values between forward and impl lead to overload resolution issues. * simplified pragma handling and callConv checks Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> * partially working * cgexprs issue * It works! * comment clean-up * clean-up asserts, comments, and other bits * add isGenericParams, inline isGeneric queries * seeing if this is sufficiently consistent * can use this approach or continue it in a further PR * commentary about nullary generics and clean-ups * fixed a mistake in PNode isGenericRoutine * Some small cleanups * Small cleanup * for func lambdas ensure we use lambda pragmas * add some basic compileTime func tests * [ci skip] remove comments Co-authored-by: Clyybber <Clyybber@users.noreply.github.com> Co-authored-by: Clyybber <darkmine956@gmail.com>
* followup #16067 --spellSuggest (#17401)Timothee Cour2021-03-171-3/+5
| | | | | | | * followup #16067 --spellSuggest * enable --spellSuggest by default * fixup
* fix #2844 #3911; add --spellsuggest to suggest symbols in scope with similar ↵Timothee Cour2021-03-161-32/+69
| | | | | | | spellings on undefined symbol error (#16067) * add --spellsuggest to suggest symbols in scope with similar spellings on undefined symbol errors * implement --spellsuggest with 0 arguments
* IC: bugfixes (WIP) (#16836)Andreas Rumpf2021-02-021-4/+17
| | | | | | | | * minor improvements * IC: added the required logic for compilerProcs * LazySym ftw * we need this testing logic * reimplement the old way we use for module package creation * fixes a regression; don't pick module names if you can avoid it
* IC: next steps (#16550)Andreas Rumpf2021-01-071-26/+30
| | | | | | | | | | | | | | | | | | * cleanups * ast.nim: cleanups * IC: no more sym.tab field, stored externally in the module graph * nimble compiles again * rodfiles: store bitwidth of integers and the endianness in the cookie because we serialize 'int' directly * rodfiles: added compilerproc and export sections * rodfiles: added all the missing sections * rodfiles: track the missing information * IC: architecture for lazy loading of proc bodies * make tests green again * completed the lazy loading of proc bodies * symbol lookup integration, part 1 * symbol lookup integration, part 2 * symbol lookup integration, part 3 * make tcompilerapi work again * rodfiles: fixed config change handling
* big steps torwards an efficient, simple IC implementation (#16543)Andreas Rumpf2021-01-021-1/+1
| | | | | | | | | | | | | | | | | | | * reworked ID handling * the packed AST now has its own ID mechanism * basic serialization code works * extract rodfiles to its own module * rodfiles: store and compare configs * rodfiles: store dependencies * store config at the end * precise dependency tracking * dependency tracking for rodfiles * completed loading of PSym, PType, etc * removed dead code * bugfix: do not realloc seqs when taking addr into an element * make IC opt-in for now * makes tcompilerapi green again * final cleanups Co-authored-by: Andy Davidoff <github@andy.disruptek.com>
* refactorings to prepare the compiler for IC (#15935)Andreas Rumpf2020-12-171-58/+243
| | | | | | | | | | | | | | * added ic specific Nim code; WIP * make the symbol import mechanism lazy; WIP * ensure that modules can be imported multiple times * ambiguity checking * handle converters and TR macros properly * make 'enum' test category green again * special logic for semi-pure enums * makes nimsuggest tests green again * fixes nimdata * makes nimpy green again * makes more important packages work