---
title: "1.8 Common mistakes"
url: https://una-lang.org/en/learn/hello/common-mistakes/
release: v0.4.0
edition: "0.2"
---

# 1.8 Common mistakes

Each mistake is a small change to `day-to-day/src/morning.una`, followed by what `una check .` reports. Read each diagnostic as [If `una check` finds a mistake](https://una-lang.org/en/learn/hello/your-first-program-hello-world/#if-una-check-finds-a-mistake) shows: the message, then the place, then the help.

## 1.8.1 Single quotes (U0001)

:::mistake
Write a text between single quotes:

```diff include="day-to-day..mistakes/1:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -50,3 +50,3 @@
   rule()
-  section("Hours", notice: opening_hours())
+  section('Hours', notice: opening_hours())
   section("Shipping", notice: shipping_cutoff())
```

```text include="mistakes/1/expected/rendered.txt#L1-L9"
[U0001] Error: invalid character `'`; text literals use double quotes
    ╭─[ src/morning.una:51:11 ]
    │
 51 │   section('Hours', notice: opening_hours())
    │           ┬
    │           ╰── invalid character `'`; text literals use double quotes
    │
    │ Note: run `una explain U0001` for an explanation
────╯
```

*Why:* a text in Una is written between double quotes, `"`. A single quote, `'`, is not a character the language uses outside a text, so the check reports it, once for each quote: the two diagnostics point at columns 11 and 17 of the same line. Curly quotes, `“` and `”`, which some editors type in place of `"`, give the same code.

*Fix:* write `"Hours"`, with the straight double quote of your keyboard. See [U0001](https://una-lang.org/en/docs/errors/U0001/).
:::

## 1.8.2 A comment with `//` (U0101)

:::mistake
Start a comment with `//`, as some other languages do:

```diff include="day-to-day..mistakes/2:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -2,3 +2,3 @@
 
--- The notices that the console of the store prints each morning, when the store opens.
+// The notices that the console of the store prints each morning, when the store opens.
 
```

```text include="mistakes/2/expected/rendered.txt#L1"
[U0101] Error: unexpected `/`, expected a declaration
```

*Why:* in Una a comment starts with `--`. `//` is not a comment, so the check reads the line as code. Outside a function, a module holds only declarations, such as functions, so the check expected a declaration and found `/` instead. The marks point at the first `/`, in column 1.

*Fix:* write `--` at the start of the comment. See [U0101](https://una-lang.org/en/docs/errors/U0101/).
:::

## 1.8.3 A public function that prints without `uses` (U3004)

:::mistake
Make `rule` public and write it on one line, without its `uses` line:

```diff include="day-to-day..mistakes/3:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -29,6 +29,3 @@
 --- Prints a line of dashes, which separates the parts of the notices.
-rule() -> Unit
-  uses @console: Console[print]
-=
-  @console.print("------------------------------")
+pub rule() -> Unit = @console.print("------------------------------")
 
```

```text include="mistakes/3/expected/rendered.txt#L1-L6"
[U3004] Error: `@console` is used here, but this code declares no `uses`, so it is pure
    ╭─[ src/morning.una:30:22 ]
    │
 30 │ pub rule() -> Unit = @console.print("------------------------------")
    │                      ────┬───
    │                          ╰───── `@console` is used here, but this code declares no `uses`, so it is pure
```

*Why:* a public function without a `uses` line is **pure**: it may do nothing outside the program. Printing is something outside the program, so the marks point at `@console`, the use the header does not allow. The private `rule` of the program could leave the line out, but a public one cannot.

*Fix:* give the header its `uses` line back, `uses @console: Console[print]`, with `=` and the body on lines of their own, or keep `rule` private. See [U3004](https://una-lang.org/en/docs/errors/U3004/).
:::

## 1.8.4 A module named unlike its file (U1008)

:::mistake
Rename the module, but not its file:

```diff include="day-to-day..mistakes/4:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -1,2 +1,2 @@
-module morning
+module notices
 
```

```text include="mistakes/4/expected/rendered.txt#L1"
[U1008] Error: module `notices` is in `src/morning.una`, which must hold module `morning`
```

*Why:* the file `src/morning.una` must hold the module `morning`: `una` finds a module from its file, and a file from its module, so the two names must agree. A second diagnostic, `U7002`, follows: `entry` in `una.toml` names the module `morning`, which the package no longer has.

*Fix:* write `module morning`. To rename the module, rename the file and the `entry` in `una.toml` with it. See [U1008](https://una-lang.org/en/docs/errors/U1008/).
:::

## 1.8.5 Indenting by four spaces (U0003)

:::mistake
Indent a step of a body by four spaces:

```diff include="day-to-day..mistakes/5:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -38,3 +38,3 @@
 =
-  @console.print(heading)
+    @console.print(heading)
   @console.print(notice)
```

```text include="mistakes/5/expected/rendered.txt#L1-L10"
[U0003] Error: inconsistent indentation of 4 spaces; expected 0 or 2
    ╭─[ src/morning.una:39:1 ]
    │
 39 │     @console.print(heading)
    │ ──┬─
    │   ╰─── inconsistent indentation of 4 spaces; expected 0 or 2
    │
    │ Help 1: repair 1: indent with 2 spaces; edit src/morning.una:39:1..39:5 to "  "
    │
    │ Help 2: repair 2: remove the indentation; edit src/morning.una:39:1..39:5 to ""
```

*Why:* Una indents by two spaces, always: a body's steps by two, and nothing deeper in this chapter. A line indented by four belongs to no level the check knows, so it reports the line and offers two repairs, since it cannot tell which level you meant.

*Fix:* indent by two spaces, as the first repair says. Many code editors insert four spaces for the [[Tab]] key; set yours to two. See [U0003](https://una-lang.org/en/docs/errors/U0003/).
:::

## 1.8.6 A second argument without its label (U2004)

:::mistake
Leave out the label of `section`'s second argument:

```diff include="day-to-day..mistakes/6:src/morning.una" context="1"
--- a/src/morning.una
+++ b/src/morning.una
@@ -50,3 +50,3 @@
   rule()
-  section("Hours", notice: opening_hours())
+  section("Hours", opening_hours())
   section("Shipping", notice: shipping_cutoff())
```

```text include="mistakes/6/expected/rendered.txt#L1"
[U2004] Error: argument 2 of `section` needs a label; only the first argument may go without one
```

*Why:* every argument after the first carries its parameter's name, so that a call says what each value is. Here the second argument, `opening_hours()`, is a call, not the name `notice`, so it is not labeled. The message names the argument by its place, 2, and the function, `section`.

*Fix:* write `notice: opening_hours()`, as the `Help` line of the diagnostic says, or let `una fix .` make that edit. See [U2004](https://una-lang.org/en/docs/errors/U2004/).
:::
