-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing statement order in generics can cause type mismatches #16128
Comments
IMO we should always allow passing the relevant hash/comparator to algorithms, it's explicit and more flexible, in particular doesn't affect unrelated code (if different hash/comparator is needed), as done in C++, D and other languages. This can be done in a backward compatible way and zero-cost way, avoiding a function pointer overhead even without lto |
Good to know that this at least somewhat known issue. Even though it might be considered duplicate I would still prefer to leave it open, since this is a particularly tricky to reproduce, so more examples would be nice to have. Is there any way currently to deal with this right now? Or I need to somehow instantiate needed generics earlier (by explicitly stating this limitation in documentation and carefully watching order of imports each time?). PS: I'm also in favor of passing |
I somehow managed to trigger another generic sandwich or whatever it is called, with symboms very similar to nim-lang/Nim#16128 - can't get string from `Table[string, string]`, things worked until I had another instantiation of the table before one in ptree. For some reason `std/tables` is the only module that triggers that kind of bugs for me, though considering /how/ it is implemented internally it should not come out as a surprise. Basicallyt an ideal environment to trigger things like that - multiple spliced `{.dirty.}` template instantiations, generics on top of generics, things are partially shared with multiple other modules (like hashes etc).
Was fixed in #22828 |
closes #1969, closes #7547, closes #7737, closes #11838, closes #12283, closes #12714, closes #12720, closes #14053, closes #16118, closes #19670, closes #22645 I was going to wait on these but regression tests even for recent PRs are turning out to be important in wide reaching PRs like #24010. The other issues with the working label felt either finnicky (#7385, #9156, #12732, #15247), excessive to test (#12405, #12424, #17527), or I just don't know what fixed them/what the issue was (#16128: the PR link gives a server error by Github, #12457, #12487).
closes nim-lang#4774, closes nim-lang#7385, closes nim-lang#10019, closes nim-lang#12405, closes nim-lang#12732, closes nim-lang#13270, closes nim-lang#13799, closes nim-lang#15247, closes nim-lang#16128, closes nim-lang#16175, closes nim-lang#16774, closes nim-lang#17527, closes nim-lang#20880, closes nim-lang#21346
Changing statement order in
simpleTreeDiff
causes compilation error. I'm not entirely sure if this is a bug, or some insanely convoluted generic interaction, but since the behavior of the compiler wildly differs only based on the order of generic instantiations it is probably a bug.Example
Current Output
Expected Output
No compilation errors
Additional
I added
static: echo typeof ...
intables.[]=
to printf-debug instantiation. Concreted code now is (module runnable example and documentation):And it produces different results based on order of the statements in code above or whether
var tmp: Table[string, seq[string]]
is present. When I try to compile example it outputsWhen I remove
var tmp: Table[string, seq[string]]
compilations succeeds, printing outWhich is what one could expect (
t.data
generic parameters are the same as in table itself).Nim version
The text was updated successfully, but these errors were encountered: