Home / Docs / Diagnostics

U2037: A decimal scale out of place

Release v0.4.0

In edition 0.5 (preview), a decimal scale is in a place where it would not fit.

Why Una rejects it

A Decimal[s] holds an exact number with s digits after the point, and its scale is part of the type (spec/29 §16, ADR 0120). The scale is an integer literal from 0 to 38. A value never loses a digit silently, so the checker refuses every place where a scale would not fit:

How to fix it

The repair at a glance

src/demo.unadiff
  module demo

- pub price() -> Decimal[2] = 19.995
+ pub price() -> Decimal[3] = 19.995

Failing example

ita.unauna
ita demo
  version 0.1.0
  edition 0.5
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub price() -> Decimal[2] = 19.995

Fixed example

ita.unauna
ita demo
  version 0.1.0
  edition 0.5
ita.lockuna
lock 1

solver
  encoding "una-smt-1"
  name "z3"
  version "5.1.0"
  logic "QF_UFLIA"
  steps 5000000
  seed 0
src/demo.unauna
module demo

pub price() -> Decimal[3] = 19.995