Skip to content
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] alias using __refitem__ fails to compile with "value doesn't have a memory type" #2543

Open
mikowals opened this issue May 6, 2024 · 0 comments
Labels
bug Something isn't working mojo-repo Tag all issues with this label

Comments

@mikowals
Copy link
Contributor

mikowals commented May 6, 2024

Bug description

Trying to use a struct that implements __refitem__ in an alias gives a compiler error: error: value doesn't have a memory type. Related to excluded InlineArray tests and #2372.

Steps to reproduce

from memory import UnsafePointer
 
 
@value
struct Foo:
    var data: UnsafePointer[Int]
 
    fn __init__(inout self):
        pass
 
    @always_inline
    fn __refitem__[
        mutability: __mlir_type.`i1`, self_life: AnyLifetime[mutability].type
    ](
        self: Reference[Self, mutability, self_life]._mlir_type,
        i: Int,
    ) -> Reference[Int, mutability, self_life]:
        var ptr = Reference(self)[].data
        return ptr[]
 
 
fn main():
    alias foo = Foo()
    _ = foo.__refitem__[__mlir_attr.`0: i1`, __lifetime_of(foo)](0)

Compiler output:

error: value doesn't have a memory type
    _ = foo.__refitem__[__mlir_attr.`0: i1`, __lifetime_of(foo)](0)
                                             ^~~~~~~~~~~~~~~~~~
mojo: error: failed to parse the provided Mojo source module

Using the foo[0] shorthand is a different error. I assume this is correct that it can not infer parameters but the root cause is the error given above when all parameters are explicit.

error: invalid call to '__refitem__': callee expects 2 parameters, but 0 were specified
    _ = foo[0]
        ~~~^~~
/Users/mikowals/projects/mojo/stdlib/scratch.mojo:12:8: note: function declared here
    fn __refitem__[
       ^
mojo: error: failed to parse the provided Mojo source module

System information

- macOS Sonoma Version 14.4.1 (23E224)
- mojo 2024.5.323 (1d9276ea)
- modular 0.7.2 (d0adc668)
@mikowals mikowals added bug Something isn't working mojo-repo Tag all issues with this label labels May 6, 2024
@ematejska ematejska added mojo-repo Tag all issues with this label and removed mojo-repo Tag all issues with this label labels May 6, 2024
@JoeLoser JoeLoser added the blocker label May 10, 2024 — with Linear
@JoeLoser JoeLoser removed the blocker label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working mojo-repo Tag all issues with this label
Projects
None yet
Development

No branches or pull requests

3 participants