Conditional Conformance Based on Origin

I'm trying to get a better understanding of origins and mutability. I'd like to try and write a function that have a mutable origin. For example, I'd like something like:
from memory.pointer import Pointer

@value
struct Foo[mut: Bool, //, *, origin: Origin[mut]]:
var _data: Pointer[type=Int, origin=origin]

fn set(self: Foo[origin=MutableAnyOrigin], i: Int):
self._data[] = i


fn foo(mut f: Foo, val: Int):
f.set(val)
from memory.pointer import Pointer

@value
struct Foo[mut: Bool, //, *, origin: Origin[mut]]:
var _data: Pointer[type=Int, origin=origin]

fn set(self: Foo[origin=MutableAnyOrigin], i: Int):
self._data[] = i


fn foo(mut f: Foo, val: Int):
f.set(val)
The code above doesn't compile, and gives the following error:
error: invalid call to 'set': self argument cannot be converted from 'Foo[origin=origin]' to 'Foo[origin=MutableAnyOrigin]'
f.set(val)
~~~~~^~~~~
error: invalid call to 'set': self argument cannot be converted from 'Foo[origin=origin]' to 'Foo[origin=MutableAnyOrigin]'
f.set(val)
~~~~~^~~~~
Does anyone know if this is possible in the language?
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?