metagn
cfd69bad1a
fix wrong subtype relation in tuples & infer some conversions ( #23228 )
...
fixes #18125
Previously a tuple type like `(T, int)` would match an expected tuple
type `(U, int)` if `T` is a subtype of `U`. This is wrong since the
codegen does not handle type conversions of individual tuple elements in
a type conversion of an entire tuple. For this reason the compiler
already does not accept `(float, int)` for a matched type `(int, int)`,
however the code that checked for which relations are unacceptable
checked for `< isSubtype` rather than `<= isSubtype`, so subtypes were
not included in the unacceptable relations.
Update: Now only considered unacceptable when inheritance is used, as in
[`paramTypesMatch`](3379d26629/compiler/sigmatch.nim (L2252-L2254) ).
Ideally subtype relations that don't need conversions, like `nil`,
`seq[empty]`, `range[0..5]` etc would be their own relation
`isConcreteSubtype` (which would also allow us to differentiate with
`openArray[T]`), but this is too big of a refactor for now.
To compensate for this making things like `let x: (Parent, int) =
(Child(), 0)` not compile (they would crash codegen before anyway but
should still work in principle), type inference for tuple constructors
is updated such that they call `fitNode` on the fields and their
expected types, so a type conversion is generated for the individual
subtype element.
2024-01-18 21:19:29 +01:00
..
2023-12-18 17:40:30 +01:00
2023-12-13 10:29:58 +01:00
2023-12-12 16:54:50 +01:00
2023-08-06 14:26:21 +02:00
2023-12-15 10:20:57 +01:00
2023-12-18 17:40:30 +01:00
2023-12-15 12:59:56 +01:00
2023-12-13 10:29:58 +01:00
2023-12-17 18:43:52 +01:00
2023-02-22 20:34:20 +01:00
2023-10-11 17:44:14 +02:00
2023-08-06 14:26:21 +02:00
2023-12-15 10:20:57 +01:00
2024-01-11 11:23:42 +01:00
2022-09-28 15:05:01 +02:00
2022-11-30 21:51:13 +01:00
2024-01-18 14:40:22 +01:00
2023-12-25 07:12:54 +01:00
2022-09-27 10:57:47 +02:00
2023-12-15 10:20:57 +01:00
2023-12-15 10:20:57 +01:00
2023-10-29 14:48:11 +01:00
2023-12-13 10:29:58 +01:00
2023-10-29 14:48:11 +01:00
2023-12-15 10:20:57 +01:00
2023-12-15 08:13:25 +01:00
2023-10-29 14:48:11 +01:00
2023-11-20 21:12:13 +01:00
2023-06-18 16:06:14 +02:00
2023-12-15 10:20:57 +01:00
2023-12-17 12:29:46 +01:00
2017-01-07 22:35:09 +01:00
2022-06-10 20:40:08 +02:00
2023-10-29 14:48:11 +01:00
2023-12-15 10:20:57 +01:00
2023-08-06 14:26:21 +02:00
2023-12-23 09:22:49 +01:00
2023-12-17 18:43:52 +01:00
2023-11-20 21:12:13 +01:00
2023-12-12 16:54:50 +01:00
2023-12-15 10:20:57 +01:00
2023-12-15 10:20:57 +01:00
2023-10-16 00:01:33 +02:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2023-12-15 08:13:25 +01:00
2023-09-01 06:41:39 +02:00
2023-10-29 14:48:11 +01:00
2023-12-15 08:13:25 +01:00
2020-06-01 19:21:41 +02:00
2023-12-15 10:20:57 +01:00
2024-01-18 21:12:13 +01:00
2023-12-15 08:13:25 +01:00
2023-12-14 16:25:34 +01:00
2024-01-02 07:49:54 +01:00
2023-12-13 10:29:58 +01:00
2024-01-13 12:00:55 +01:00
2023-12-13 10:39:10 +01:00
2023-12-15 08:13:25 +01:00
2024-01-11 11:23:42 +01:00
2023-10-29 14:48:11 +01:00
2023-12-22 08:49:51 +01:00
2023-08-06 14:26:21 +02:00
2023-11-04 17:46:59 +08:00
2024-01-01 12:21:19 +01:00
2023-12-13 10:29:58 +01:00
2021-01-12 09:36:51 +01:00
2023-12-12 16:54:50 +01:00
2023-12-06 18:17:57 +01:00
2023-12-15 08:13:25 +01:00
2024-01-05 08:17:08 +01:00
2023-03-03 07:36:38 +01:00
2023-12-15 08:13:25 +01:00
2022-03-23 20:34:53 +01:00
2023-12-16 07:05:57 +01:00
2023-11-30 14:05:45 +01:00
2023-12-14 17:04:09 +01:00
2023-12-15 08:13:25 +01:00
2023-12-15 08:13:25 +01:00
2023-06-30 23:03:25 +02:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2023-12-12 16:54:50 +01:00
2023-10-29 14:48:11 +01:00
2023-04-17 20:55:22 +02:00
2023-10-29 14:48:11 +01:00
2023-12-31 22:56:48 +08:00
2023-08-06 14:26:21 +02:00
2023-04-24 06:52:37 +02:00
2023-10-29 14:48:11 +01:00
2023-12-17 09:01:00 +01:00
2022-08-24 09:44:16 +02:00
2023-11-20 21:12:13 +01:00
2023-10-29 14:48:11 +01:00
2023-12-17 18:43:52 +01:00
2023-12-13 10:29:58 +01:00
2023-03-03 07:36:38 +01:00
2023-10-29 14:48:11 +01:00
2018-05-27 19:19:12 +02:00
2023-12-25 07:12:54 +01:00
2023-10-29 14:48:11 +01:00
2023-12-15 08:13:25 +01:00
2023-07-02 22:36:05 +02:00
2023-12-24 15:22:10 +01:00
2023-10-29 14:48:11 +01:00
2023-10-29 14:48:11 +01:00
2023-11-06 18:33:28 +01:00
2023-08-10 14:26:40 +02:00
2020-09-11 01:04:07 +02:00
2023-10-29 14:48:11 +01:00
2023-12-17 18:43:52 +01:00
2023-12-17 18:43:52 +01:00
2023-12-14 16:25:34 +01:00
2024-01-18 21:19:29 +01:00
2023-12-15 08:13:25 +01:00
2023-12-12 16:54:50 +01:00
2023-12-22 08:49:51 +01:00
2024-01-11 07:45:11 +01:00
2023-12-15 10:20:57 +01:00
2024-01-11 11:23:42 +01:00
2023-12-15 08:13:25 +01:00
2023-12-15 08:13:25 +01:00
2023-12-19 10:24:36 +01:00
2024-01-13 14:09:34 +01:00
2022-12-11 16:58:50 +01:00
2024-01-07 07:48:32 +01:00
2024-01-18 21:14:27 +01:00
2024-01-17 11:59:54 +01:00
2023-12-15 10:20:57 +01:00
2024-01-18 21:19:29 +01:00
2023-11-20 21:12:13 +01:00
2023-12-14 16:25:34 +01:00
2023-12-15 08:13:25 +01:00
2023-12-13 10:29:58 +01:00
2024-01-15 18:36:03 +01:00
2023-10-29 14:48:11 +01:00
2023-08-10 14:26:40 +02:00
2023-12-02 05:28:24 +01:00
2023-12-12 16:54:50 +01:00
2023-10-29 14:48:11 +01:00
2023-12-14 16:25:34 +01:00
2024-01-15 18:36:03 +01:00
2023-10-29 14:48:11 +01:00
2023-12-15 10:20:57 +01:00
2023-12-19 17:27:24 +01:00
2023-12-12 16:54:50 +01:00
2023-08-21 20:08:00 +02:00
2023-12-15 10:20:57 +01:00
2024-01-18 14:50:36 +01:00
2023-08-10 14:26:40 +02:00
2023-12-15 10:20:57 +01:00
2023-08-18 16:47:47 +02:00
2023-10-29 14:48:11 +01:00
2023-12-17 18:43:52 +01:00
2023-12-25 07:12:54 +01:00