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

Nested functions are called by name, so the wrong function is called #8587

Closed
bluss opened this issue Aug 18, 2013 · 3 comments
Closed

Nested functions are called by name, so the wrong function is called #8587

bluss opened this issue Aug 18, 2013 · 3 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@bluss
Copy link
Member

bluss commented Aug 18, 2013

The following example shows that in method h(), it returns the result of the function nested inside the method f().

pub struct X;

impl X {
    fn f(&self) -> int {
        #[inline(never)]
        fn inner() -> int {
            0
        }
        inner()
    }

    fn g(&self) -> int {
        #[inline(never)]
        fn inner_2() -> int {
            1
        }
        inner_2()
    }

    fn h(&self) -> int {
        #[inline(never)]
        fn inner() -> int {
            2
        }
        inner()
    }
}

mod tests {
    use super::*;

    #[test]
    fn test_function() {
        let n = X;
        assert_eq!(n.f(), 0);
        assert_eq!(n.g(), 1);
        assert_eq!(n.h(), 2);       // This test fails!
    }
}

Output:

running 1 test
task <unnamed> failed at 'assertion failed: `(left == right) && (right == left)` (left: `0`, right: `2`)', nestf.rs:38
test tests::test_function ... FAILED

failures:
    tests::test_function

test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
@alexcrichton
Copy link
Member

This may be vaguely related to #2074

@bluss
Copy link
Member Author

bluss commented Sep 8, 2013

The tests now pass as of master at 79e78c4

I suspect you fixed this issue alexcrichton

@huonw
Copy link
Member

huonw commented Sep 8, 2013

Flagged as needstest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants