sharkdp / numbat

A statically typed programming language for scientific computations with first class support for physical dimensions and units
https://numbat.dev
Apache License 2.0
1.26k stars 53 forks source link

Improve identifier clash errors when conflicting identifier is declared in `@aliases` decorator #570

Closed triallax closed 1 month ago

triallax commented 2 months ago

i'm implementing https://github.com/sharkdp/numbat/issues/441, and there's a confusing error due to a conflict happening here:

@name("Malaysian ringgit")
@url("https://en.wikipedia.org/wiki/Malaysian_ringgit")
@aliases(malaysian_ringgits, MYR: short, myr, RM, rm)
unit malaysian_ringgit: Money = EUR / exchange_rate("MYR")

and the error:

>>> usd
error: identifier clash in definition
    ┌─ Module 'units::time', File <builtin>/modules/units/time.nbt:32:6
    │
 32 │ unit year: Time = 365.242_188_1 days
    │      ---- Previously defined here
    │
    ┌─ Module 'units::currencies', File <builtin>/modules/units/currencies.nbt:104:6
    │
104 │ unit malaysian_ringgit: Money = EUR / exchange_rate("MYR")
    │      ^^^^^^^^^^^^^^^^^ identifier is already in use

the conflict is between myr as malaysian_ringgit and myr as milliyear, but the error points to the primary identifiers malaysian_ringgit and year instead of the relevant aliases, and it also doesn't mention anything about the unit prefix

can this error be made clearer?