-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
mirtypes: fix regression with cyclic generic object types (#1398)
## Summary Fix cyclic generic object types instantiated with tuple types as one of the arguments causing C compiler errors under some circumstances. ## Details * the type merging logic in `mirtypes` now uses `sighashes`, which is able to handle cyclic types * previously, `Obj[(int,)]` and `Obj[tuple[x: int]]` were not being merged into one when `Obj` is cyclic * this led to C compiler errors when assigning between such types, or when the type has hooks (explicit or synthesized) that are called
- Loading branch information
Showing
2 changed files
with
30 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
tests/lang_callable/generics/tequal_instantiation_with_tuple.nim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
discard """ | ||
description: ''' | ||
Ensure that two instantiations of a cyclic generic object type are | ||
considered equal at every level (type system, backend, run-time) when | ||
one of them is instantiated with a named tuple and the other with an | ||
unnamed one | ||
''' | ||
knownIssue.vm: "``vmtypegen`` considers the two types distinct" | ||
""" | ||
|
||
type Recursive[T] = object | ||
# the same problem occurred when a ``ref`` type is used | ||
self: ptr Recursive[T] | ||
val: T | ||
|
||
# it's important that both tuples are comprised of the exact same types | ||
var x: Recursive[(int, int)] | ||
var y: Recursive[tuple[a, b: int]] | ||
x = y |