# `type.constraint_loosened`

A type that builds on another sets a looser bound than the one it inherits, such as a higher `max_length`.

Area 2, [Values and types](/docs/values-and-types.md); not declinable; the next step is usually the agent's.

## Why Jadpo refuses it

A refinement, a type that builds on another, can only add to the rules
it inherits. Every rule along the chain still holds, so a value of
`ShortProductName` still needs `ProductName`'s `max_length: 120`. A
looser bound would never apply, and a reader would believe a value can
be longer than it can.

## What it looks like

main.jadpo:

```jadpo
type ProductName = Text {
    min_length: 1
    max_length: 120
}

type ShortProductName = ProductName {
    max_length: 150
}
```

```text
error: `max_length: 150` loosens `ProductName`'s `max_length: 120`
 --> main.jadpo:7:5
  |
7 |     max_length: 150
  |     ^^^^^^^^^^ looser than `max_length: 120`
  reason: A refinement only adds to the rules of the type it builds on, and every rule along the way still holds, so a value still needs `max_length: 120` and this one would never apply.
  next: Make `max_length` at most 120, or remove it (agent)
  rule: type.constraint_loosened
  help: https://jadpo.dev/docs/errors/type.constraint_loosened

check failed: 1 error, 1 file
```

`(agent)` at the end of the `next:` line means your coding agent can make
the fix itself.

## How to fix it

**If the new type should be stricter**, give it a bound within the
inherited one:

```jadpo
    max_length: 40
```


A `ShortProductName` is now at most 40 characters, and it can still be
used wherever a `ProductName` is expected.

**If the inherited bound is the one you want**, remove the line:

```jadpo
type ProductName = Text {
    min_length: 1
    max_length: 120
}

type ShortProductName = ProductName {}
```

`ShortProductName` keeps `ProductName`'s rules, 1 to 120 characters, and
is still its own type.

When the new type really needs longer values, build it on `Text` itself
rather than on `ProductName`. It then can't be passed where a
`ProductName` is expected without a construction, which checks the
shorter bound.

## Related

- [Named types](/docs/named-types.md)
- [Constraints](/docs/named-types.md#constraints)
- [When one type can stand in for another](/docs/when-one-type-can-stand-in-for-another.md)
