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

Segfault with | (or) and tuples and strs in match #6338

Closed
Dretch opened this issue May 8, 2013 · 2 comments
Closed

Segfault with | (or) and tuples and strs in match #6338

Dretch opened this issue May 8, 2013 · 2 comments
Labels
A-codegen Area: Code generation

Comments

@Dretch
Copy link
Contributor

Dretch commented May 8, 2013

The following code compiles:

fn main() {
    match ((1, ~"a"), (2, ~"b")) {
        ((1, a), (2, b)) |
        ((2, b), (1, a)) => {
            println(a);
            println(b);
        },
        _ => fail!(),
    }
}

But when it runs if fails like so (on 64 bit linux):

b
Segmentation fault (core dumped)

Note that it prints "b" before segfaulting, but that is actually incorrect - the first println should print "a".

@emberian
Copy link
Member

emberian commented Jul 7, 2013

Reproduced

@dim-an
Copy link
Contributor

dim-an commented Aug 10, 2013

The same problem here:

fn main() {
    match (1, 2, 3) {
        (1, a, b) | (2, b, a) => {
                printfln!(a);
                printfln!(b);
            },
            _ => fail!(),
    }
}

This code unexpectedly outputs:

3
3

The problem (as I understand it), is in variable binding. We bind variables for both patterns in the same arm, and different pattern overwrite each other.

I will try to fix it in the nearest future.

bors added a commit that referenced this issue Aug 18, 2013
Pointers to bound variables shouldn't be stored before checking pattern,
otherwise piped patterns can conflict with each other (issue #6338).

Closes #6338.
@bors bors closed this as completed in f4b8854 Aug 18, 2013
flip1995 pushed a commit to flip1995/rust that referenced this issue Nov 20, 2020
Rustup

r? `@ghost`

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants