---
title: "U4005: Invalid policy (public `via`, or type mismatch)"
url: https://una-lang.org/en/docs/errors/U4005/
release: v0.4.0
source: https://github.com/una-lang/una/blob/v0.4.0/crates/una-explain/explain/U4005.md
---

# U4005: Invalid policy (public `via`, or type mismatch)

A policy's `via` function does not meet one of the conditions below. The message says which of these fails.

## Why Una rejects it

A policy's `via` function computes the declassified value, and the policy is its only entry point (`spec/07 §5`):

- The `via` function is a private function of the policy's trusted module.
- Its one parameter has the type of `from` and its result the type of `to`, refinements included, since only labels differ.
- It has no `requires` clause, since a policy call checks its argument against `from` only.
- No other code uses it.

Inside it no label is checked.

## The repair at a glance

`src/keys.una`

```diff
  trusted module keys

  pub policy mask
    from secret[PII] Text
    to internal Text
    via masked
    purpose "show the last digits"
    owner privacy

- pub masked(t: secret[PII] Text) -> internal Text = t
+ masked(t: secret[PII] Text) -> internal Text = t
```

## Failing example

`una.toml`

```toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.1"

[labels]
categories = ["PII"]

[trusted]
modules = ["keys"]
```

`src/keys.una`

```una
trusted module keys

pub policy mask
  from secret[PII] Text
  to internal Text
  via masked
  purpose "show the last digits"
  owner privacy

pub masked(t: secret[PII] Text) -> internal Text = t
```

## Fixed example

`una.toml`

```toml
[package]
name = "demo"
version = "0.1.0"
edition = "0.1"

[labels]
categories = ["PII"]

[trusted]
modules = ["keys"]
```

`src/keys.una`

```una
trusted module keys

pub policy mask
  from secret[PII] Text
  to internal Text
  via masked
  purpose "show the last digits"
  owner privacy

masked(t: secret[PII] Text) -> internal Text = t
```
