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

Reference parameters copied in Move #11

Open
egroge opened this issue Jul 28, 2020 · 0 comments
Open

Reference parameters copied in Move #11

egroge opened this issue Jul 28, 2020 · 0 comments
Labels
bug Something isn't working language Issues with the flint-2 Flint language implementation or features move ir Code generation for Libra

Comments

@egroge
Copy link
Collaborator

egroge commented 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:

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.

@egroge 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 mrRachar changed the title Unable to pass round mutable references to structs in move Reference parameters copied in Move Jul 28, 2020
@mrRachar mrRachar added this to the Spec compatibility milestone Jul 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working language Issues with the flint-2 Flint language implementation or features move ir Code generation for Libra
Projects
None yet
Development

No branches or pull requests

2 participants