-
Notifications
You must be signed in to change notification settings - Fork 2.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
[BUG]: Mojo variadics don't work with non-trivial register-only types. #1941
Comments
Tried also iterating over that, which fails to iterator not being mutable or something like that.
|
Your second example works fine on top-of-tree and will work in 24.2: from python import Python
fn main() raises:
var json = Python.import_module("json")
var a = json.loads('{"a": 1, "b": 2}')
print(a.values())
for v in a.values():
print(v) It prints:
Your first example: from python import Python
def main():
var json = Python.import_module("json")
a = json.loads('{"a": 1}')
print(a.values())
print(a.values()[0]) crashes on the subscript operator as you mentioned. We should fix that to give a better error message. The
as expected |
@akirchhoff-modular helped track this down - this is caused by register-only types being handled by VariadicList instead of VariadicListMem, so their copy constructors don't get run correctly. There is a big migration to move the variadic list representation over to this new form, which can hopefully help, but I'm not exactly sure when it will converge |
This is fixed in the next update, thank you for reporting this! |
VariadicList is implemented with AnyRegType so it can't invoke copy constructors. This means we can't use it for non-trivial types like PythonObject. Switch variadics of non-trivial register type to use VariadicListMem instead: we'd eventually like to remove VariadicList but are not quite ready for that. This fixes variadics with things like PythonObject and Fixes #37362 and Fixes #1941 MODULAR_ORIG_COMMIT_REV_ID: fd3cdc841773c009ccce94110e722961fa2a1b82
Bug description
Application crashes as soon as I try to do
a.values()[0]
I would expect either working code or compile time error for using brackets in this case. Actually now that I think I might be confused with bracket getitem and bracket compile time parameters... so feel free to close if was complete user error.
Steps to reproduce
Pretty minimal example code included:
System information
Running in WSL2 (ubuntu22) mojo 24.1.0 (55ec12d6) modular 0.5.1 (1b608e3d)
The text was updated successfully, but these errors were encountered: