Home / Docs / Diagnostics

U1002: Duplicate definition

Release v0.4.0

U1002 reports a name that is defined more than once in its scope.

Why Una rejects it

A name is defined once in its scope:

A local binding cannot rebind another local that is still in scope, so every use of a name inside a function means one binding. A module may reuse a prelude name, and a local may reuse any name that is not local: the inner one wins.

In edition 0.2, a kind, a variant or a capability cannot take the name of a built-in type (Int, Nat, Bool, Text, Unit, Hashed, List, Option, Result, the fixed-width integer types, Map and Entry): pub kind Text = Short | Long is U1002, since it would silently replace Text in its module (ADR 0079).

The repair at a glance

diff
  module demo

  pub double(x: Int) -> Int
  =
-   let x = x * 2
-   x
+   let doubled = x * 2
+   doubled

Failing example

una
module demo

pub double(x: Int) -> Int
=
  let x = x * 2
  x

Fixed example

una
module demo

pub double(x: Int) -> Int
=
  let doubled = x * 2
  doubled