You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we wish to pass a struct to some method, and have that method change things about the struct, we will need to pass the struct by reference. This does not currently work correctly. Consider the following:
struct A {
var foo: Int
public init() {
foo = 0
}
public func increment() {
foo = foo + 1
}
}
contract MyContract {
var a: A
}
MyContract :: (any) {
public init() {
a = A()
}
public func contractIncrement() {
increment(&self.a)
}
func increment(a: inout A) {
// The a passed in refers to a different struct, so the following has no external effect
a.increment()
}
}
We wish to pass self.a to increment, which will then somehow alter it. It seems that currently, a new a: inout A gets created in the move code, and then this is the one that is altered. Thus self.a is unchanged.
The text was updated successfully, but these errors were encountered:
egroge
added
bug
Something isn't working
move ir
Code generation for Libra
language
Issues with the flint-2 Flint language implementation or features
labels
Jul 28, 2020
mrRachar
changed the title
Unable to pass round mutable references to structs in move
Reference parameters copied in Move
Jul 28, 2020
If we wish to pass a struct to some method, and have that method change things about the struct, we will need to pass the struct by reference. This does not currently work correctly. Consider the following:
We wish to pass self.a to increment, which will then somehow alter it. It seems that currently, a new a: inout A gets created in the move code, and then this is the one that is altered. Thus self.a is unchanged.
The text was updated successfully, but these errors were encountered: