mojo
mojo copied to clipboard
[BUG] error: invalid call to 'address_of', address_of does not work with keyword borrowed, although it does work with keyword owned and inout 🤷♂️😨😰
Bug description
struct S:
var x: Int
var y: Int
fn __init__(inout self, a: Int, b: Int):
self.x = a
self.y = b
print("address_of a :", Pointer.address_of(a))
print("address_of b :", Pointer.address_of(b))
print("address_of self.x :", Pointer.address_of(self.x))
print("address_of self.y :", Pointer.address_of(self.y))
fn main():
var s = S(1, 3)
Output
Compile error:
/source/prog.mojo:8:51: error: invalid call to 'address_of': could not deduce parameter 'type' of parent struct 'Pointer'
print("address_of a :", Pointer.address_of(a))
~~~~~~~~~~~~~~~~~~^~~
/source/prog.mojo:1:1: note: struct declared here
struct S:
^
/source/prog.mojo:1:1: note: function declared here
struct S:
^
/source/prog.mojo:9:51: error: invalid call to 'address_of': could not deduce parameter 'type' of parent struct 'Pointer'
print("address_of b :", Pointer.address_of(b))
~~~~~~~~~~~~~~~~~~^~~
/source/prog.mojo:1:1: note: struct declared here
struct S:
^
/source/prog.mojo:1:1: note: function declared here
struct S:
^
mojo: error: failed to parse the provided Mojo
Steps to reproduce
- Include relevant code snippet or link to code that did not work as expected.
- If applicable, add screenshots to help explain the problem.
- If using the Playground, name the pre-existing notebook that failed and the steps that led to failure.
- Include anything else that might help us debug the issue.
System information
- What OS did you do install Mojo on ? https://docs.modular.com/mojo/playground
- Provide version information for Mojo by pasting the output of `mojo -v`
- Provide Modular CLI version by pasting the output of `modular -v`