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

Returning multiple values in a function #1160

Closed
derekzx opened this issue Dec 26, 2018 · 1 comment
Closed

Returning multiple values in a function #1160

derekzx opened this issue Dec 26, 2018 · 1 comment
Labels
bug Bug that shouldn't change language semantics when fixed.

Comments

@derekzx
Copy link

derekzx commented Dec 26, 2018

Version Information

  • vyper Version: 0.1.0
  • OS: 18.04

What's your issue about?

Unable to set tuples aka #605

Please include information like:

  • full output of the error you received
    test_a remains as 100

  • what command you ran
    checking events emitted using truffle
    truffle test

  • the code that caused the failure

Creation: event({
    _test_a: uint256
})
test_a : uint256
test_b : uint256
test_c : uint256
test_x : uint256


@public
def __init__():
    self.test_a = 100
    
@public
def test1() -> (uint256, uint256):
    log.Creation(self.test_x)
    return (1,2)

@public
def test():
    (self.test_b, self.test_a) = self.test1()
    log.Creation(self.test_a)
    log.Creation(self.test_b)

Test Code:

const test = artifacts.require("test");
const assert = require("chai").assert;
const truffleAssert = require('truffle-assertions');

contract("test", (accounts) => {
    let test1;
    const fundingAccount = accounts[0];

    beforeEach(async () => {
        test1 = await test.new({from: fundingAccount});
    });
    
    it("should receive event", async() => {
        let tx = await test1.test();
        truffleAssert.eventEmitted(tx, 'Creation', (ev) => {
            return ev._test_a == 2;
        });
    });
});

I am not sure whether I did it wrong but the goal would be to set 2 variables at once.

Cute Animal Picture

image

@derekzx
Copy link
Author

derekzx commented Dec 26, 2018

Referenced #1113 .

Unable to work ONLY when setting global variables. In-function variables are able to be changed.

##...code before

@public
def test():
    c : uint256
    d : uint256
    e : uint256
    d , e = self.test1()
##more code after ....

Is able to work but my previous post is still unable to work

@jacqueswww jacqueswww added the bug Bug that shouldn't change language semantics when fixed. label Jan 2, 2019
charles-cooper added a commit to charles-cooper/vyper that referenced this issue Jan 31, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug that shouldn't change language semantics when fixed.
Projects
None yet
Development

No branches or pull requests

2 participants