Skip to content

Support var in tuple destructuring #9573

@JRI98

Description

@JRI98

To be consistent with other uses of var, I think it should also be supported in the context of tuple destructuring statements.

main! = |_| {
	Ok({})
}

g = |index| {
	(0, index)
}

f = |i| {
	(_, var $index) = g(i)
	(_, $index) = g($index)

	$index
}
➜  roc git:(main) ✗ roc check main.roc 
-- DUPLICATE DEFINITION --------------------------

The name $index is being redeclared in this scope.

The redeclaration is here:
   ┌─ .../roc/main.roc:11:6
   │
11 │    (_, $index) = g($index)
   │        ^^^^^^

But $index was already defined here:
   ┌─ .../roc/main.roc:10:6
   │
10 │    (_, var $index) = g(i)
   │        ^^^^^^^^^^

-- INVALID ASSIGNMENT TO ITSELF ------------------

The value $index is assigned to itself, which would cause an infinite loop at runtime.

Only functions can reference themselves (for recursion). For non-function values, the right-hand side must be fully computable without referring to the value being assigned.

   ┌─ .../roc/main.roc:11:18
   │
11 │    (_, $index) = g($index)
   │                    ^^^^^^


Found 1 error(s) and 1 warning(s) in 5693ms for main.roc.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions