summary refs log tree commit diff stats
path: root/tests/errmsgs
Commit message (Collapse)AuthorAgeFilesLines
* Revert "make default values typed in proc AST same as param sym AST" (#24191)metagn2024-09-271-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reverts #24184, reopens #12942, reopens #19118 #24184 seems to have caused a regression in https://github.com/c-blake/thes and https://github.com/c-blake/bu/blob/main/rp.nim#L84 reproducible with `git clone https://github.com/c-blake/cligen; git clone https://github.com/c-blake/thes; cd thes; nim c -p=../cligen thes`. Changing the `const` to `let` makes it compile. A minimization that is probably the same issue is: ```nim const a: seq[string] = @[] proc foo(x = a) = echo typeof(x) echo x import macros macro resemFoo() = result = getImpl(bindSym"foo") block: resemFoo() # Error: cannot infer the type of parameter 'x' ``` This should be a regression test in a future reimplementation of #24184.
* make default values typed in proc AST same as param sym AST (#24184)metagn2024-09-271-2/+2
| | | | | | fixes #12942, fixes #19118 This is the exact same as #20735 but maybe the situation has improved after #24065.
* fix nimsuggest crash with arrow type sugar (#24185)metagn2024-09-271-1/+1
| | | | | | | | | fixes #24179 The original fix made it so calls to `skError`/`skUnknown` (in this case `->`, for some reason `sugar` couldn't be imported) returned an error node, however this breaks tsug_accquote for some reason I don't understand (it even parses as `tsug_accquote.discard`) so I've just added a guard based on the stacktrace.
* fix segfault in generic param mismatch error, skip typedesc (#24140)metagn2024-09-194-2/+25
| | | | | | | | | | | | | | refs #24010, refs https://github.com/nim-lang/Nim/issues/24125#issuecomment-2358377076 The generic mismatch errors added in #24010 made it possible for `nArg` to be `nil` in the error reporting since it checked the call argument list, not the generic parameter list for the mismatching argument node, which causes a segfault. This is fixed by checking the generic parameter list immediately on any generic mismatch error. Also the `typedesc` type is skipped for the value of the generic params since it's redundant and the generic parameter constraints don't have it.
* make `var`/pointer types not match if base type has to be converted (#24130)metagn2024-09-181-2/+2
| | | | | | | | | | | | | | | | | | | split again from #24038, fixes https://github.com/status-im/nimbus-eth2/pull/6554#issuecomment-2354977102 `var`/pointer types are no longer implicitly convertible to each other if their element types either: * require an int conversion or another conversion operation as long as it's not to `openarray`, * are subtypes with pointer indirection, Previously any conversion below a subrange match would match if the element type wasn't a pointer type, then it would error later in `analyseIfAddressTaken`. Different from #24038 in that the preview define that made subrange matches also fail to match is removed for a simpler diff so that it can be backported.
* show symchoices as ambiguous in overload type mismatches (#24077)metagn2024-09-095-0/+34
| | | | | | | | fixes #23397 All ambiguous symbols generate symchoices for call arguments since #23123. So, if a type mismatch receives a symchoice node for an argument, we now treat it as an ambiguous identifier and list the ambiguous symbols in the error message.
* proper errors for subscript overloads (#24068)metagn2024-09-064-33/+93
| | | | | | | | | | The magic `mArrGet`/`mArrPut` subscript overloads always match, so if a subscript doesn't match any other subscript overloads and isn't a regular language-handled subscript, it creates a fake overload mismatch error in `semArrGet` that doesn't have any information (gives stuff like "first mismatch at index: 0" for every single mismatch). Instead of generating the fake mismatches, we only generate the fake mismatch for `mArrGet`/`mArrPut`, and process every overload except them as a real call and get the errors from there.
* handle explicit generic routine instantiations in sigmatch (#24010)metagn2024-09-024-22/+52
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #16376 The way the compiler handled generic proc instantiations in calls (like `foo[int](...)`) up to this point was to instantiate `foo[int]`, create a symbol for the instantiated proc (or a symchoice for multiple procs excluding ones with mismatching generic param counts), then perform overload resolution on this symbol/symchoice. The exception to this was when the called symbol was already a symchoice node, in which case it wasn't instantiated and overloading was called directly ([these lines](https://github.com/nim-lang/Nim/blob/b7b1313d21deb687adab2b4a162e716ba561a26b/compiler/semexprs.nim#L3366-L3371)). This has several problems: * Templates and macros can't create instantiated symbols, so they couldn't participate in overloaded explicit generic instantiations, causing the issue #16376. * Every single proc that can be instantiated with the given generic params is fully instantiated including the body. #9997 is about this but isn't fixed here since the instantiation isn't in a call. The way overload resolution handles explicit instantiations by itself is also buggy: * It doesn't check constraints. * It allows only partially providing the generic parameters, which makes sense for implicit generics, but can cause ambiguity in overloading. Here is how this PR deals with these problems: * Overload resolution now always handles explicit generic instantiations in calls, in `initCandidate`, as long as the symbol resolves to a routine symbol. * Overload resolution now checks the generic params for constraints and correct parameter count (ignoring implicit params). If these don't match, the entire overload is considered as not matching and not instantiated. * Special error messages are added for mismatching/missing/extra generic params. This is almost all of the diff in `semcall`. * Procs with matching generic parameters now instantiate only the type of the signature in overload resolution, not the proc itself, which also works for templates and macros. Unfortunately we can't entirely remove instantiations because overload resolution can't handle some cases with uninstantiated types even though it's resolved in the binding (see the last 2 blocks in `texplicitgenerics`). There are also some instantiation issues with default params that #24005 didn't fix but I didn't want this to become the 3rd huge generics PR in a row so I didn't dive too deep into trying to fix them. There is still a minor instantiation fix in `semtypinst` though for subscripts in calls. Additional changes: * Overloading of `[]` wasn't documented properly, it somewhat is now because we need to mention the limitation that it can't be done for generic procs/types. * Tests can now enable the new type mismatch errors with just `-d:testsConciseTypeMismatch` in the command. Package PRs: - using fork for now: [combparser](https://github.com/PMunch/combparser/pull/7) (partial generic instantiation) - merged: [cligen](https://github.com/c-blake/cligen/pull/233) (partial generic instantiation but non-overloaded + template) - merged: [neo](https://github.com/andreaferretti/neo/pull/56) (trying to instantiate template with no generic param)
* allow `untyped` arguments to fail to compile in overload mismatch error (#23984)metagn2024-08-201-0/+37
| | | | | | | | | | | | | | | | fixes #8697, fixes #9620, fixes #23265 When matching a `template` with an `untyped` argument fails because of a mismatching typed argument, `presentFailedCandidates` tries to sem every single argument to show their types, but trying to type the `untyped` argument can fail if it's supposed to use an injected symbol, so we get an unrelated error message like "undeclared identifier". Instead we use `tryExpr` as the comment suggests, setting the type to `untyped` if it fails to compile. We could also maybe check if an `untyped` argument is expected in its place and not try to compile the expression if it is but this would require a bit of reorganizing the code here and IMO it's better to have the information of what type it would be if it can be typed.
* make routine implicitly gensym when other gensym symbol exists again (#23842)metagn2024-07-161-1/+1
| | | | | | | | | | | | | 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.
* fixes #3011; handles meta fields defined in the ref object (#23818)ringabout2024-07-111-10/+24
| | | | | | | | | | | | | | | | | | | | | | | 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 #22672; Destructor not called for result when exception is thrown (#23267)ringabout2024-06-061-0/+9
| | | fixes #22672
* 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 #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
* 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
* stop gensym identifiers hijacking routine decl names in templates (#23392)metagn2024-04-091-0/+25
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* 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.
* don't use previous bindings of `auto` for routine return types (#23207)metagn2024-01-171-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fixes #23200, fixes #18866 #21065 made it so `auto` proc return types remained as `tyAnything` and not turned to `tyUntyped`. This had the side effect that anything previously bound to `tyAnything` in the proc type match was then bound to the proc return type, which is wrong since we don't know the proc return type even if we know the expected parameter types (`tyUntyped` also [does not care about its previous bindings in `typeRel`](https://github.com/nim-lang/Nim/blob/ab4278d2179639f19967431a7aa1be858046f7a7/compiler/sigmatch.nim#L1059-L1061) maybe for this reason). Now we mark `tyAnything` return types for routines as `tfRetType` [as done for other meta return types](https://github.com/nim-lang/Nim/blob/18b5fb256d4647efa6a64df451d37129d36e96f3/compiler/semtypes.nim#L1451), and ignore bindings to `tyAnything` + `tfRetType` types in `semtypinst`. On top of this, we reset the type relation in `paramTypesMatch` only after creating the instantiation (instead of trusting `isInferred`/`isInferredConvertible` before creating the instantiation), using the same mechanism that `isBothMetaConvertible` uses. This fixes the issues as well as making the disabled t15386_2 test introduced in #21065 work. As seen in the changes for the other tests, the error messages give an obscure `proc (a: GenericParam): auto` now, but it does give the correct error that the overload doesn't match instead of matching the overload pre-emptively and expecting a specific return type. tsugar had to be changed due to #16906, which is the problem where `void` is not inferred in the case where `result` was never touched.
* fixes #23180; fixes #19805; prohibits invalid tuple unpacking code in for ↵ringabout2024-01-131-2/+2
| | | | | | loop (#23185) fixes #23180 fixes #19805
* delay resolved procvar check for proc params + acknowledge unresolved ↵metagn2024-01-111-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | statics (#23188) fixes #23186 As explained in #23186, generics can transform `genericProc[int]` into a call `` `[]`(genericProc, int) `` which causes a problem when `genericProc` is resemmed, since it is not a resolved generic proc. `[]` needs unresolved generic procs since `mArrGet` also handles explicit generic instantiations, so delay the resolved generic proc check to `semFinishOperands` which is intentionally not called for `mArrGet`. The root issue for [t6137](https://github.com/nim-lang/Nim/blob/devel/tests/generics/t6137.nim) is also fixed (because this change breaks it otherwise), the compiler doesn't consider the possibility that an assigned generic param can be an unresolved static value (note the line `if t.kind == tyStatic: s.ast = t.n` below the change in sigmatch), now it properly errors that it couldn't instantiate it as it would for a type param. ~~The change in semtypinst is just for symmetry with the code above it which also gives a `cannot instantiate` error, it may or may not be necessary/correct.~~ Now removed, I don't think it was correct. Still possible that this has unintended consequences.
* ambiguous identifier resolution (#23123)metagn2024-01-011-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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`
* fixes #23060; `editDistance` wrongly compare the length of rune strings (#23062)ringabout2023-12-131-0/+5
| | | fixes #23060
* fixes #22996; `typeAllowedCheck` for default fields (#22998)ringabout2023-11-291-0/+7
| | | fixes #22996
* fixes #22753; Nimsuggest segfault with invalid assignment to table (#22781)ringabout2023-10-022-5/+45
| | | | | | | | 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-0/+24
| | | | fixes #10542 revives and close #20169
* make expressions opt in to symchoices (#22716)metagn2023-09-181-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* type annotations for variable tuple unpacking, better error messages (#22611)metagn2023-09-011-1/+1
| | | | | | | | | * 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-1/+1
| | | | | | | | | | | | | | | * 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>
* fixes #6499; disallow built-in procs used as procvars (#22291)ringabout2023-07-191-0/+6
|
* fixes #22049; fixes #22054; implicit conversion keeps varness (#22097)ringabout2023-06-161-0/+9
| | | | | | | | | | | | | | | | | | | | | * fixes #22054; codegen for var tuples conv * rethink fixes * add test cases * templates only * fixes var tuples * keep varness no matter what * fixes typ.isNil * make it work for generics * restore isSubrange * add a test case as requested
* some test cleanups & category reorganization (#22010)metagn2023-06-067-0/+59
| | | | | | | | | | | | | | | | | * 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
* properly disallow unresolved generic proc values (#22005)metagn2023-06-051-0/+10
| | | | | | | * properly disallow unresolved generic proc values * mirrors semoperand * shallow efTypeAllowed, add back special case
* clean up SOME pending/xxx/issue link comments (#21826)metagn2023-05-111-22/+6
| | | | | * clean up SOME pending/xxx/issue link comments * great
* cheap fix for #10853 + better tuple subscript error message (#21767)metagn2023-05-022-0/+5
| | | | | | | * cheap fix for #10853 * also better tuple subscript error message * weird
* alias syntax fixes, improvements and tests (#21671)metagn2023-04-221-10/+10
| | | | | | | | | | | | | * 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.}
* make --exceptions:quirky work with C++ (#21581)Andreas Rumpf2023-03-311-1/+1
| | | | | * make --exceptions:quirky work with C++ * make tests green again
* hopefully easier to understand error message (#21585)Andreas Rumpf2023-03-301-2/+2
|
* closes #16654; add a test case (#21478)ringabout2023-03-061-0/+12
|
* tests/errmsgs/tcall_with_default_arg.nim: sync (#21237)Anna2023-03-011-1/+1
|
* tests: explicitly enable stack traces where needed (#21236)Anna2023-03-013-17/+20
| | | | | * tests/assert/tassert_c.nim: explicitly enable stack traces * tests/errmsgs: explicitly enable stack traces
* fixes #19795; fixes #11852; fixes #19974; remove parsing pipeline, Nim now ↵ringabout2023-02-221-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | parses the whole module at one time (#21379) * fixes #19795; remove parse pipeline * isScript * fixes nimscriptapi * don't touch reorder * check script * fixes tests * it seems implicit imports of system cause troubles * access the first child of `nkStmtList` * ignore comments * minor messages * perhaps increases hloLoopDetector * the module is a stmtList, which changes the errors * fixes nimdoc * fixes tlinter * fixes nim secret tests * fixes arc_misc * fixes nim secret tests again * safe; fixes one more test * GlobalError is the root cause too * fixes parsing errors * put emit types to the cfsForwardTypes section * fixes #11852; `{.push checks:off}` now works in procs * disable navigator * fixes nimdoc * add tests for JS * fixes nimsuggest
* close #21257 (#21275)metagn2023-01-181-0/+20
| | | | | * close #21257 * fix generics
* fixes #21195; `std/assertions` continue to use `sysFatal` when ↵ringabout2022-12-291-2/+2
| | | | | | | | | | | | | `nimPreviewSlimSystem` is not defined (#21196) * fixes #21195; `std/assertions` continue to use `sysFatal` * try includes * make `std/assertions` self-contained * fixes tests * fixes tests
* fixes #14444; add `genLineDir` before assignment (#21201)ringabout2022-12-291-0/+14
| | | | | | | * fixes #14444; add `genLineDir` before raises * add a test case * fixes differently
* less verbose type mismatch messages (#21191)ringabout2022-12-282-0/+44
| | | | | | | | | * less verbose type mismatch messages * Update compiler/types.nim * fixes i386 * fixes i386
* fix for bad error message with const in case statement (#21182)metagn2022-12-271-0/+7
| | | | | | | * preliminary fix for bad error message with const * add test case * fix tmatrixconcept and tmatrixlib
* Named arguments in commands + many grammar fixes (#20994)metagn2022-12-062-3/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Breaking parser changes, implement https://github.com/nim-lang/RFCs/issues/442 Types are separated from expressions and better reflected in the grammar. * add test * more accurate grammar * fix keyword typedescs * accept expressions in proc argument lists * CI "fixes" * fixes * allow full ref expressions again, adapt old tests * cleanup, fix some tests * improve grammar, try and revert semtypes change * restrict sigil binding to identOrLiteral * fix, should have caught this immediately * add changelog entry, fix double not nil bug * correct grammar * change section * fix * real fix hopefully * fix test * support LL(1) for tuples * make grammar.txt too
* revert #20719; relieve `std/assertions` of the `sysFatal` dep (#20743)ringabout2022-11-041-4/+5
| | | | | | | * Revert "make `system/fatal` importable (#20718)" This reverts commit d735c447d35948ef6fda8270d1665cbd66c4636a. * relieve `std/assertions` of the sysFatal dep
* fix semcase on tySequence and tyObject #20283 #19682 (#20339)Bung2022-11-011-0/+29
| | | | | | | | | | | | | * fix semcase on tySequence and tyObject #20283 #19682 * use better arg name * avoiding returns nil use errorNode instead, clean code * use efNoDiagnostics flag * remove tests/errmsgs/t19682.nim * combine 2 test cases to one file