Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Mutable variables - let 1 become 0 #6873

@michalmuskala

Description

@michalmuskala

Describe the bug
In some specific cases pattern matching doesn't do what it's supposed to - instead it mutates variables.

To Reproduce
Given the following snippet:

-module(test).

-export([test/0]).

test() ->
    Zero = 0,
    One = 1,

    Result = One = Zero,

    io:format("~p ~p~n", [Zero, One]),
    Result.

Compiling the test module and running test:test() from the shell produces:

1> test:test().
0 0
0

Expected behavior
The code should crash with match error, and variables should remain immutable.

Affected versions
Tested with the latest maint-25 and maint-24 branches. This correctly fails on current master, even emitting a warning during compilation with erlc.

Additional context
Originally discovered by @jcpetruzza

Metadata

Metadata

Assignees

Labels

bugIssue is reported as a bugteam:VMAssigned to OTP team VM

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions