summary refs log tree commit diff stats
path: root/tests/template
Commit message (Collapse)AuthorAgeFilesLines
* don't typecheck `untyped` + allow void `typed` template param default values ↵metagn2024-10-031-0/+41
| | | | | | | | | | | (#24219) Previously, the compiler never differentiated between `untyped`/`typed` argument default values and other types, it considered any parameter with a type as typed and called `semExprWithType`, which both typechecked it and disallowed `void` expressions. Now, we perform no typechecking at all on `untyped` template param default values, and call `semExpr` instead for `typed` params, which allows expressions with `void` type.
* treat resolved symbols on RHS of module qualification as identifiers (#24180)metagn2024-09-273-0/+29
| | | | | | | | | | | | | | | | | | fixes #19866 given #23997 When searching for a module-qualified symbol, `qualifiedLookUp` tries to obtain the raw identifier from the RHS of the dot field. However it only does this when the RHS is either an `nkIdent` or an `nkAccQuoted` node, not when the node is a resolved symbol or a symchoice, such as in templates and generics when the module symbol can't be resolved yet. Since the LHS is a module symbol when the compiler checks for this, any resolved symbol information doesn't matter, since it has to be a member of the module. So we now obtain the identifier from these nodes as well as the unresolved identifier nodes. The test is a bit niche and possibly not officially supported, but this is likely a more general problem and I just couldn't think of another test that would be more "proper". It's better than the error message `'a' has no type` at least.
* only merge valid implicit pragmas to routine AST, include templates (#24171)metagn2024-09-263-0/+23
| | | | | | | | | | | | | fixes #19277, refs #24169, refs #18124 When pragmas are pushed to a routine, if the routine symbol AST isn't nil by the time the pushed pragmas are being processed, the pragmas are implicitly added to the symbol AST. However this is done without restriction on the pragma, if the pushed pragma isn't supposed to apply to the routine, it's still added to the routine. This is why the symbol AST for templates wasn't set before the pushed pragma processing in #18124. Now, the pragmas added to the AST are restricted to ones that apply to the given routine. This means we can set the template symbol AST earlier so that the pragmas get added to the template AST.
* make `genericsOpenSym` work at instantiation time, new behavior in `openSym` ↵metagn2024-09-182-1/+40
| | | | | | | | | | | | | | | | | | | | | | | | | | (#24111) alternative to #24101 #23892 changed the opensym experimental switch so that it has to be enabled in the context of the generic/template declarations capturing the symbols, not the context of the instantiation of the generics/templates. This was to be in line with where the compiler gives the warnings and changes behavior in a potentially breaking way. However `results` [depends on the old behavior](https://github.com/arnetheduck/nim-results/blob/71d404b314479a6205bfd050f4fe5fe49cdafc69/results.nim#L1428), so that the callers of the macros provided by results always take advantage of the opensym behavior. To accomodate this, we change the behavior of the old experimental option that `results` uses, `genericsOpenSym`, so that ignores the information of whether or not symbols are intentionally opened and always gives the opensym behavior as long as it's enabled at instantiation time. This should keep `results` working as is. However this differs from the normal opensym switch in that it doesn't generate `nnkOpenSym`. Before it was just a generics-only version of `openSym` along with `templateOpenSym` which was only for templates. So `templateOpenSym` is removed along with this change, but no one appears to have used it.
* fix segfault in effect tracking for sym node with nil type (#24114)metagn2024-09-171-0/+19
| | | | | | | | | | | | | | | | | | | | | | | | | fixes #24112 Sym nodes in templates that could be open are [given `nil` type](https://github.com/nim-lang/Nim/blob/22d2cf217597468ace8ba540d6990b1f6d8a816a/compiler/semtempl.nim#L274) when `--experimentalOpenSym` is disabled so that they can be semchecked to give a warning since #24007. The first nodes of object constructors (in this case) and in type conversions don't replace their first node (the symbol) with a typechecked one, they only call `semTypeNode` on it and leave it as is. Effect tracking checks if the type of a sym node has a destructor to check if the node type should be replaced with the sym type. But this causes a segfault when the type of the node is nil. To fix this, we always set the node type to the sym type if the node type is nil. Alternatively `semObjConstr` and `semConv` could be changed to set the type of their first node to the found type but I'm not sure if this would break anything. They could call `semExprWithType` on the first node but `semTypeNode` would still have to be called (maybe call it before?). This isn't a problem if the sym node has a type but is just nested in `nkOpenSym` or `nkOpenSymChoice` which have nil type instead (i.e. with openSym enabled), so maybe this still is the "most general" solution, I don't know.
* implement template default values using other params (#24073)metagn2024-09-111-0/+15
| | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23506 #24065 broke compilation of template parameter default values that depended on other template parameters. But this was never implemented anyway, actually attempting to use those default values breaks the compiler as in #23506. So these are now implemented as well as fixing the regression. First, if a default value expression uses any unresolved arguments (generic or normal template parameters) in a template header, we leave it untyped, instead of applying the generic typechecking (fixing the regression). Then, just before the body of the template is about to be explored, the default value expressions are handled in the same manner as the body as well. This captures symbols including the parameters, so the expression is checked again if it contains a parameter symbol, and marked with `nfDefaultRefsParam` if it does (as an optimization to not check it later). Then when the template is being evaluated, when substituting a parameter, if we try to substitute with a node marked `nfDefaultRefsParam`, we also evaluate it as we would the template body instead of passing it as just a copy (the reason why it never worked before). This way we save time if a default value doesn't refer to another parameter and could just be copied regardless.
* opensym for templates + move behavior of opensymchoice to itself (#24007)metagn2024-08-282-0/+269
| | | | | | | | | | | | | | | | | | | | | | | fixes #15314, fixes #24002 The OpenSym behavior first added to generics in #23091 now also applies to templates, since templates can also capture symbols that are meant to be replaced by local symbols if the context imports symbols with the same name, as in the issue #24002. The experimental switch `templateOpenSym` is added to enable this behavior for templates only, and the experimental switch `openSym` is added to enable it for both templates and generics, and the documentation now mainly mentions this switch. Additionally the logic for `nkOpenSymChoice` nodes that were previously wrapped in `nkOpenSym` now apply to all `nkOpenSymChoice` nodes, and so these nodes aren't wrapped in `nkOpenSym` anymore. This means `nkOpenSym` can only have children of kind `nkSym` again, so it is more in line with the structure of symchoice nodes. As for why they aren't merged with `nkOpenSymChoice` nodes yet, we need some way to signal that the node shouldn't become ambiguous if other options exist at instantiation time, we already captured a symbol at the beginning and another symbol can only replace it if it's closer in scope and unambiguous.
* make routine implicitly gensym when other gensym symbol exists again (#23842)metagn2024-07-161-0/+12
| | | | | | | | | | | | | fixes #23813, partially reverts #23392 Before #23392, if a `gensym` symbol was defined before a proc with the same name in a template even with an `inject` annotation, the proc would be `gensym`. After #23392 the proc was instead changed to be `inject` as long as no `gensym` annotation was given. Now, to keep compatibility with the old behavior, the behavior is changed back to infer the proc as `gensym` when no `inject` annotation is given, however an explicit `inject` annotation will still inject the proc. This is also documented in the manual as the old behavior was undocumented and the new behavior is slightly different.
* closes #13426; adds a test case (#23642)ringabout2024-05-241-0/+87
| | | closes #13426
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-091-0/+37
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* closes #22846; adds a test case (#23374)ringabout2024-03-081-0/+9
| | | closes #22846
* don't transform typed bracket exprs to `[]` calls in templates (#23175)metagn2024-01-071-0/+38
| | | | | | | | | | | | | | fixes #22775 It's pre-existing that [`prepareOperand` doesn't typecheck expressions which have types](https://github.com/nim-lang/Nim/blob/a4f3bf374238df96f0982b7106e3702da6b485b1/compiler/sigmatch.nim#L2444). Templates can take typed subscript expressions, transform them into calls to `[]`, and then have this `[]` not be resolved later if the expression is nested inside of a call argument, which leaks an untyped expression past semantic analysis. To prevent this, don't transform any typed subscript expressions into calls to `[]` in templates. Ditto for curly subscripts (with `{}`) and assignments to subscripts and curly subscripts (with `[]=` and `{}=`).
* second test case haul for templates and generics (#22728)metagn2023-09-193-5/+22
| | | | closes #8390, closes #11726, closes #8446, closes #21221, closes #7461, closes #7995
* correct logic for qualified symbol in templates (#22577)metagn2023-08-281-0/+4
| | | | | | | * correct logic for qualified symbol in templates fixes #19865 * add test
* test case haul for old generic/template/macro issues (#22564)metagn2023-08-274-8/+97
| | | | | | | | | | | | * test case haul for old generic/template/macro issues closes #12582, closes #19552, closes #2465, closes #4596, closes #15246, closes #12683, closes #7889, closes #4547, closes #12415, closes #2002, closes #1771, closes #5121 The test for #5648 is also moved into its own test from `types/tissues_types` due to not being joinable. * fix template gensym test
* fix generic param substitution in templates (#22535)metagn2023-08-251-0/+80
| | | | | | | * fix generic param substitution in templates fixes #13527, fixes #17240, fixes #6340, fixes #20033, fixes #19576, fixes #19076 * fix bare except in test, test updated packages in CI
* Fix #21532: Check if template return is untyped (#22517)SirOlaf2023-08-231-0/+8
| | | | | | | | | * Don't ignore return in semTemplateDef * Add test --------- Co-authored-by: SirOlaf <>
* fixes #21231; template with module as parameter elides usage/checking of ↵ringabout2023-06-211-0/+10
| | | | | | | module name specifier (#22109) * fixes #21231; template with module as parameter elides usage/checking of module name specifier * add a test case
* add tests to close #7223, close #11733 (#22111)metagn2023-06-163-8/+53
| | | | | add test to close #7223, close #11733 closes #7223, closes #11733, were fixed by #22076
* consider object types as declarative in templates (#22106)metagn2023-06-161-0/+12
| | | | | | | | | * consider object types as declarative in templates fixes #16005 * correct logic for nkRecList children, inject fields * don't actually inject fields
* fix dot calls with resolved symbols in templates (#22076)metagn2023-06-122-0/+32
| | | | | | | | | | | | | * fix dot calls with resolved symbols in templates * make old code work * fix custom number literals test * remove leftover debug marker * enable "bug 9" test too * fix renderer, add test for #7085
* some test cleanups & category reorganization (#22010)metagn2023-06-062-5/+33
| | | | | | | | | | | | | | | | | * clean up some test categories * mention exact slice issue * magics into system * move trangechecks into overflow * move tmemory to system * try fix CI * try fix CI * final CI fix
* support generic void return type for templates (#21934)metagn2023-05-271-0/+6
| | | fixes #21920
* fix #21727 (#21729)metagn2023-04-261-0/+11
|
* alias syntax fixes, improvements and tests (#21671)metagn2023-04-223-16/+91
| | | | | | | | | | | | | * 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.}
* document general use of `_`, error message, fixes (#21584)metagn2023-03-301-1/+1
| | | | | | | | | | | | * 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
* close #11705; add a testcase (#21128)ringabout2022-12-181-0/+17
|
* deprecate `do:` meaning `do ():` + misc cleanup (#20927)metagn2022-12-061-1/+1
| | | | | | | | | | | | | | | | | * test disable do: block lambda lifting * fix last test [skip ci] * deprecate `do:` meaning `do ():` + misc cleanup closes https://github.com/nim-lang/RFCs/issues/486 * oops * fix * no idea what could be causing nimsuggest failure other than this * ensure ci works
* fix #19149 Invalid codegen when returning var tuple from a template (#20762)Bung2022-11-061-0/+19
| | | | | * fix #19149 Invalid codegen when returning var tuple from a template * fix type
* alternate fix + test for #12094, refs #13804 (#20686)metagn2022-10-291-0/+11
|
* fixes #1027; disallow templates to use ambiguous identifiers (#20631)ringabout2022-10-243-0/+24
| | | | | | | | | | | | | | | | | | | | * test qualifiedLookUp in templates * check later * add testcase * add 4errormsg * Update tests/template/m1027a.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> * Update tests/template/m1027b.nim Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com> Co-authored-by: Andreas Rumpf <rumpf_a@web.de> Co-authored-by: Clay Sweetser <Varriount@users.noreply.github.com>
* [backport] Handle nkOpenSymChoice for nkAccQuoted in considerQuotedIdent ↵SirOlaf2022-10-181-0/+15
| | | | | | | | | | | | (#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 #19700 Crash when passing a template to a generic functio… (#20567)Bung2022-10-151-0/+10
| | | fix nim-lang#19700 Crash when passing a template to a generic function expecting a procedure
* pragma for sfCallsite instead of name check + better semantics, test (#20464)metagn2022-10-032-0/+37
| | | | | | | | | | | * pragma for sfCallsite instead of name check at every template definition Not documented because it seems to be for internal use? Should also make it possible to make comparisons and setops imports, but this doesn't have to be done. I can reuse a name like `cursor` for the pragma as well, added a new name just to be safe. * make sfCallsite recursive, add tests
* defaults to ORC (#19972)ringabout2022-09-231-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * defaults to Orc * bootstrap using refc * use gc * init orc defines * unregister orc * fix gc * fix commands * add prepareMutation for orc * enable deepcopy for orc * prepareMutation * more fixes * some cases * bug #20081 * partial fixes * partial fixes * fixes command line * more fixes * build Nim with refc * use gc * more fixes * rstore * orc doesn't support threadpool * more shallowCopy * more fixes * fixes unsafeNew * workarounds * small * more fixes * fixes some megatest * tcodegenbugs1 refc * fxies megatest * build nimble with refc * workaround tensordsl tests * replace shallowCopy with move * fixes action * workaround * add todo * fixes important packages * unpublic unregisterArcOrc * fixes cpp * enable windows Co-authored-by: xflywind <43030857+xflywind@users.noreply.github.com>
* fix #13515 [backport] (#20315)metagn2022-09-111-0/+16
| | | | | | | | | | | * fix #13515 * only compile test * no idea why this PR is unlocking this * don't rope in symchoices * even more restrictive
* new .redefine pragma for templates, warn on redefinition without it (#20211)metagn2022-08-233-3/+36
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * test CI for template redefinitions * adapt asyncmacro * fix quote * fix again * try something else * revert * fix ioselectors_select, disable packages CI * adapt more tests & simplify * more * more * more * rename to redefine, warn on implicit redefinition * basic documentation [skip ci] * Update compiler/lineinfos.nim Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com> Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
* fix #20002 (#20004)metagn2022-07-151-0/+8
| | | | | | While this fix seems innocent, this unlocks the hidden behavior of method calls not being able to call gensym'ed routines inside templates.
* fix term rewriting with sideeffect (#19410)flywind2022-01-191-0/+19
| | | | | | | | | * fix term rewriting with sideeffect fix #6217 * add tests * Update tests/template/template_various.nim
* style usages part one (openarray => openArray) (#19321)flywind2022-01-043-4/+4
| | | | | * style usages (openArray) * revert doc changes
* improve several tests in testament (#18635)Timothee Cour2021-08-082-3/+5
| | | | | | | | | | | * silence error output from template_various.nim * any => auto in tests * avoid showing failed for parseSpec since this is expected behavior in 2 cases: tincludefile.nim, tnav1.nim * enforce InheritFromException * fixup
* exportC => exportc (#18625)Timothee Cour2021-07-311-1/+1
|
* fix #18113 (#18124)Saem Ghani2021-05-311-0/+14
|
* close #9534 add testcase (#17607)flywind2021-04-011-0/+21
|
* semTemplateDef and t17433 clean-ups (#17448)Saem Ghani2021-03-221-3/+3
| | | | | - use `doAssert` in t17433 - use setGenericParamsMisc in semTemplateDef akin to semProcAux - pragma handling in semTemplateDef inline with semProcAux
* Fixes #17433; gensym callDef return in templ body (#17445)Saem Ghani2021-03-221-0/+16
|
* use lowercase --define switches (#17283)flywind2021-03-071-1/+1
|
* Fix #12595 (#16874)konsumlamm2021-01-311-2/+8
|
* Add testcase for #5993 (#16789)Clyybber2021-01-221-0/+16
|
* remove some noises in tests (#16448)flywind2020-12-271-3/+3
|