Commit Graph

84 Commits

Author SHA1 Message Date
metagn
fb93295344 fix compound inheritance penalty (#24775)
fixes #24773

`c.inheritancePenalty` is supposed to be used for the entire match, but
in these places the inheritance penalty of a single argument overrides
the entire match penalty. The `+ ord(c.inheritancePenalty < 0)` is
copied from other places that use the same idiom, the intent is that the
existing penalty changes from -1 to 0 first to mark that it participates
in inheritance before adding the inheritance depth.

---------

Co-authored-by: Andreas Rumpf <araq4k@proton.me>
2025-03-12 17:31:33 +01:00
metagn
a18dcca744 don't try to infer array range to unresolved range (#24709)
fixes #24708
2025-02-26 22:21:03 +01:00
metagn
aeb3fe9505 test case haul to prevent pileup (#24525)
closes #6013, closes #7009, closes #9190, closes #12487, closes #12831,
closes #13184, closes #13252, closes #14860, closes #14877, closes
#14894, closes #14917, closes #16153, closes #16439, closes #17779,
closes #18074, closes #18202, closes #18314, closes #18648, closes
#19063, closes #19446, closes #20065, closes #20367, closes #22126,
closes #22820, closes #22888, closes #23020, closes #23287, closes
#23510
2024-12-09 08:11:47 +01:00
metagn
96043bdbb7 fix crash with tyBuiltInTypeClass matching itself (#24462)
fixes #24449

The standalone `seq` type is a `tyBuiltInTypeClass` with a single child
of kind `tySequence`, which itself has no children. This is also the
case for most other `tyBuiltInTypeClass` kinds. However this can cause a
crash in sigmatch when calling `isEmptyContainer` on this child type,
which expects the sequence type to have children. This check was added
in #5557 to prevent empty collections like `@[]` from matching their
respective typeclass, but it's not useful when matching against another
typeclass (which is done here to resolve an ambiguity). So to avoid the
crash, this empty container check is disabled when matching against
another typeclass.
2024-11-23 14:20:15 +01:00
metagn
45b8434c7d skip tyAlias in generic alias checks [backport:2.0] (#24417)
fixes #24415

Since #23978 (which is in 2.0), all generic types that alias to another
type now insert a `tyAlias` layer in their value. However the
`skipGenericAlias` etc code which `sigmatch` uses is not updated for
this, so `tyAlias` is now skipped in these.

The relevant code in sigmatch is:
67ad1ae159/compiler/sigmatch.nim (L1668-L1673)

This behavior is also suspicious IMO, not skipping a structural
`tyGenericInst` alias can be useful for code like #10220, but this is
currently arbitrarily decided based on "depth" and whether the alias is
to another `tyGenericInst` type or not. Maybe in the future we could
enforce the use of a nominal type.
2024-11-08 08:36:52 +01:00
metagn
0a058a6b8f better errors for standalone explicit generic instantiations (#24276)
refs #8064, refs #24010

Error messages for standalone explicit generic instantiations are
revamped. Failing standalone explicit generic instantiations now only
error after overloading has finished and resolved to the default `[]`
magic (this means `[]` can now be overloaded for procs but this isn't
necessarily intentional, in #24010 it was documented that it isn't
possible). The error messages for failed instantiations are also no
longer a simple `cannot instantiate: foo` message, instead they now give
the same type mismatch error message as overloads with mismatching
explicit generic parameters.

This is now possible due to the changes in #24010 that delegate all
explicit generic proc instantiations to overload resolution. Old code
that worked around this is now removed. `maybeInstantiateGeneric` could
maybe also be removed in favor of just `explicitGenericSym`, the `result
== n` case is due to `explicitGenericInstError` which is only for niche
cases.

Also, to cause "ambiguous identifier" error messages when the explicit
instantiation is a symchoice and the expression context doesn't allow
symchoices, we semcheck the sym/symchoice created by
`explicitGenericSym` with the given expression flags.

#8064 isn't entirely fixed because the error message is still misleading
for the original case which does `values[1]`, as a consequence of
#12664.
2024-10-18 19:06:42 +02:00
metagn
1660ddf98a make var/pointer types not match if base type has to be converted (#24130)
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.
2024-09-18 17:37:18 +02:00
metagn
fe55dcb2be test case haul before 2.2 (#24119)
closes #4774, closes #7385, closes #10019, closes #12405, closes #12732,
closes #13270, closes #13799, closes #15247, closes #16128, closes
#16175, closes #16774, closes #17527, closes #20880, closes #21346
2024-09-17 09:50:10 +08:00
metagn
04da0a6028 fix subscript magic giving unresolved generic param type (#23988)
fixes #19737

As in the diff, `semResolvedCall` sets the return type of a call to a
proc to the type of the call. But in the case of the [subscript
magic](https://nim-lang.org/docs/system.html#%5B%5D%2CT%2CI), this type
is the first generic param which is also supposed to be the type of the
first argument, but this is invalid, the correct type is the element
type eventually given by `semSubscript`. Some lines above also [prevent
the subscript magics from instantiating their
params](dda638c1ba/compiler/semcall.nim (L699))
so this type ends up being an unresolved generic param.

Since the type of the node is not `nil`, `prepareOperand` doesn't try to
type it again, and this unresolved generic param type ends up being the
final type of the node. To prevent this, we just never set the type of
the node if we encountered a subscript magic.

Maybe we could also rename the generic parameters of the subscript
magics to stuff like `DummyT`, `DummyI` if we want this to be easier to
debug in the future.
2024-08-22 07:20:20 +02:00
Ryan McConnell
c1f91c26a5 Overload resultion with generic variables an inheritance (#23870)
The test case diff is self explanatory
2024-07-24 23:59:45 +02:00
Ryan McConnell
22ba5abd63 fixes 23823; array static overload - again (#23824)
#23823
2024-07-11 22:57:17 +02:00
ringabout
e53a2ed19b fixes #20865; fixes #20987; Missing bounds check in array slicing (#23814)
fixes #20865
fixes #20987
2024-07-10 17:25:34 +02:00
Ryan McConnell
27abcdd57f fixes #23755; array static inference during overload resolution (#23760)
#23755

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-07-01 14:39:16 +02:00
metagn
ee984f8836 account for nil return type in tyProc sumGeneric (#23250)
fixes #23249
2024-01-23 22:00:34 +01:00
Ryan McConnell
74fa8ed59a Changing generic weight of tyGenericParam (#22143)
This is in reference to a [feature
request](https://github.com/nim-lang/Nim/issues/22142) that I posted.

I'm making this PR to demonstrate the suggested change and expect that
this should be scrutinized

---------

Co-authored-by: Bung <crc32@qq.com>
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2024-01-05 09:42:21 +01:00
Ryan McConnell
b2ca6bedae Make typeRel behave to spec (#22261)
The goal of this PR is to make `typeRel` accurate to it's definition for
generics:
```
# 3) When used with two type classes, it will check whether the types
# matching the first type class (aOrig) are a strict subset of the types matching
# the other (f). This allows us to compare the signatures of generic procs in
# order to give preferrence to the most specific one:
```

I don't want this PR to break any code, and I want to preserve all of
Nims current behaviors. I think that making this more accurate will help
serve as ground work for the future. It may not be possible to not break
anything but this is my attempt.

So that it is understood, this code was part of another PR (#22143) but
that problem statement only needed this change by extension. It's more
organized to split two problems into two PRs and this issue, being
non-breaking, should be a more immediate improvement.

---------

Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2023-09-30 06:34:14 +02:00
metagn
20037a4749 make var object match better than object (#22152)
* fix `var object` not matching better than `object`

fixes #13302

* remove comment for brevity

* try note

* try minimize breaks
2023-06-25 16:52:16 +02:00
metagn
02be212dae clean up SOME pending/xxx/issue link comments (#21826)
* clean up SOME pending/xxx/issue link comments

* great
2023-05-11 10:23:52 +02:00
Andreas Rumpf
48d41ab375 fixes #20645 (#20646)
* fixes #20645

* better bugfix
2022-10-24 21:41:29 +02:00
Andreas Rumpf
07b645342a fixes #3748 (#20563)
* fixes #3748

* fix the regression

* don't use the new allocator for the SSL wrapper

* fixes regression
2022-10-14 12:00:38 +02:00
ringabout
5602183234 'lock levels' are deprecated, now a noop (#20539)
* 'lock levels' are deprecated, now a noop

* fixes tests
2022-10-11 09:17:09 +02:00
metagn
f6eb1d4d7d remove {.this.} pragma, deprecated since 0.19 (#20201)
Co-authored-by: Andreas Rumpf <rumpf_a@web.de>
2022-08-23 19:44:37 +02:00
flywind
d102b2f54c deprecate unsafeAddr; extend addr (#19373)
* deprecate unsafeAddr; extend addr

addr is now available for all addressable locations, unsafeAddr is deprecated and become an alias for addr

* follow @Vindaar's advice

* change the signature of addr

* unsafeAddr => addr (stdlib)

* Update changelog.md

* unsafeAddr => addr (tests)

* Revert "unsafeAddr => addr (stdlib)"

This reverts commit ab83c99c50.

* doc changes; thanks to @konsumlamm

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>

Co-authored-by: konsumlamm <44230978+konsumlamm@users.noreply.github.com>
2022-01-16 11:08:38 +01:00
flywind
9df195ef58 style usages part one (openarray => openArray) (#19321)
* style usages (openArray)

* revert doc changes
2022-01-04 13:29:50 +01:00
Andreas Rumpf
a7cae2bda2 fixes #16325 [backport:1.4] (#18784) 2021-09-02 17:15:11 +02:00
Timothee Cour
24445d31b3 improve several tests in testament (#18635)
* 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
2021-08-08 19:28:49 +02:00
Timothee Cour
b809562c7c make megatest consistent with unjoined tests wrt newlines, honor newlines in output spec (#16151)
* fix megatest newlines
* still allow missing trailing newline for now but in a more strict way than before
2020-11-28 09:09:31 +01:00
flywind
fb60e35a54 close #8829(add testcase for #8829) (#15866) 2020-11-06 23:39:20 +08:00
flywind
3028c1be82 add testcase for #7416 (#15782) 2020-10-30 09:59:38 +01:00
jcosborn
e56d50d747 fix infinite recursion in typeRel (#15241)
* fix generic constraints

Co-authored-by: James Osborn <osborn@Jamess-MacBook-Pro.local>
2020-09-18 11:21:37 +02:00
jcosborn
d11933ad99 fix some issues overloading with generics and inheritance (#15211)
* fix some issues overloading with generics and inheritance

* fix passing procs with subtype matches
2020-08-27 12:56:38 +02:00
jcosborn
e194cb41a4 fix overloading issue with generic invocation (#15135)
* fix overloading issue with generic alias

* add test for inheritance depth
2020-08-18 08:23:19 +02:00
jcosborn
32c6146200 fix overloading case with generic alias (#15116)
* fix overloading case with generic alias

* revert reorganization of tests
2020-07-30 15:34:11 +02:00
hlaaftana
f50377986a exp. features now in correct manual, closes #11932 (#14195) 2020-05-02 22:30:08 +02:00
Andreas Rumpf
4a35d2b571 fixes #11375 (#11376) 2019-06-02 06:33:35 +02:00
Andreas Rumpf
fd16875561 fixes #8568 (#11303)
* fixes #8568

* fixes regression
2019-05-22 20:59:54 +02:00
Araq
85ac4bfff6 closes #6076 2019-05-22 15:42:34 +02:00
Araq
90e882d55b fixes #11239 2019-05-22 07:41:16 +02:00
Araq
07a0a61875 fixes #9149 [backport] 2019-01-29 14:31:43 +01:00
Arne Döring
3859878db8 megatest checks output and nimout 2018-12-11 21:23:22 +01:00
Arne Döring
1105d03644 require errormsg to be specified before file. 2018-12-11 21:23:21 +01:00
Arne Döring
e012eb1001 updated tests to be executed 2018-11-23 11:58:28 +01:00
Miran
1b17c9f693 More descriptive names of test files (#9531)
* change generic `tissues` name to more specific
* change `tvarious` to more specific names
2018-10-29 17:07:27 +01:00
Miran
749dbce4c6 Merge tests into a larger file (part 5 of ∞) (#9368)
* merge magics

* merge metatype tests

* merge method tests

* merge objects tests

* change `import future` to `import sugar`

Nim in Action tests are left with `import future`, to ensure compatibility.

* merge overload tests

* merge proc tests

* merge procvar tests

* merge range tests

* merge seq tests

* merge sets tests

* remove wrong assert from `tsets3`

* fix `jsTests`

* better fix
2018-10-16 10:50:10 +02:00
Andreas Rumpf
ae82406c8b make tests green again 2018-07-05 19:14:18 +02:00
Andreas Rumpf
0926754e68 make tests green again 2018-07-05 15:51:04 +02:00
Zahary Karadjov
b0d85b0adf Backwards-compatible support for keyword arguments in the command syntax 2018-05-07 09:37:49 +02:00
Zahary Karadjov
e678a4285d Bugfix: Allow matching on nkExprEqExpr against varargs[untyped]
This enables macros accepting arbitrary keyword arguments:

log("foo", prop1 = "bar", prop2 = "baz")

As an added bonus, simple templates with varargs arguments can now
forward their params to procs accepting keyword arguments.
2018-05-07 09:37:49 +02:00
Andreas Rumpf
74fe7a800b make tests green again 2018-05-02 13:34:54 +02:00
Andreas Rumpf
34b333b140 make tests green again 2018-04-22 07:10:55 +02:00