Skip to content

Commit

Permalink
improve naming of units in error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Vindaar committed Dec 20, 2023
1 parent 81cdc67 commit e8ee8a0
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/unchained/units.nim
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ macro `==`*[T: SomeUnit; U: SomeUnit](x: T, y: U): bool =
result = quote do:
`almostEq`(`x`.FloatType * `xScale`, `y`.FloatType * `yScale`)
else:
error("Different quantities cannot be compared! Quantity 1: " & (x.getTypeInst).repr & ", Quantity 2: " & (y.getTypeInst).repr)
error("Different quantities cannot be compared! Quantity 1: " & pretty(xCT) & ", Quantity 2: " & pretty(yCT))

macro `<`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped =
var xCT = parseDefinedUnit(x)
Expand All @@ -217,7 +217,7 @@ macro `<`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped
result = quote do:
(`x`.FloatType * `xScale` < `y`.FloatType * `yScale`)
else:
error("Different quantities cannot be compared! Quantity 1: " & (x.getTypeInst).repr & ", Quantity 2: " & (y.getTypeInst).repr)
error("Different quantities cannot be compared! Quantity 1: " & pretty(xCT) & ", Quantity 2: " & pretty(yCT))

macro `<=`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped =
var xCT = parseDefinedUnit(x)
Expand All @@ -233,7 +233,7 @@ macro `<=`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped
result = quote do:
(`x`.FloatType * `xScale` <= `y`.FloatType * `yScale`)
else:
error("Different quantities cannot be compared! Quantity 1: " & (x.getTypeInst).repr & ", Quantity 2: " & (y.getTypeInst).repr)
error("Different quantities cannot be compared! Quantity 1: " & pretty(xCT) & ", Quantity 2: " & pretty(yCT))

macro `+`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped =
var xCT = parseDefinedUnit(x)
Expand Down Expand Up @@ -262,7 +262,7 @@ macro `+`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped
defUnit(`resType`)
`resType`(`xr`.FloatType * `xScale` + `yr`.FloatType * `yScale`)
else:
error("Different quantities cannot be added! Quantity 1: " & (x.getTypeInst).repr & ", Quantity 2: " & (y.getTypeInst).repr)
error("Different quantities cannot be added! Quantity 1: " & pretty(xCT) & ", Quantity 2: " & pretty(yCT))

macro `-`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped =
var xCT = parseDefinedUnit(x)
Expand Down Expand Up @@ -293,7 +293,7 @@ macro `-`*[T: SomeUnit|SomeNumber; U: SomeUnit|SomeNumber](x: T; y: U): untyped
defUnit(`resType`)
`resType`(`xr`.FloatType * `xScale` - `yr`.FloatType * `yScale`)
else:
error("Different quantities cannot be subtracted! Quantity 1: " & (x.getTypeInst).repr & ", Quantity 2: " & (y.getTypeInst).repr)
error("Different quantities cannot be subtracted! Quantity 1: " & pretty(xCT) & ", Quantity 2: " & pretty(yCT))

proc `-`*[T: SomeUnit](x: T): T = (-(x.FloatType)).T

Expand Down Expand Up @@ -445,7 +445,7 @@ macro to*[T: SomeUnit; U: SomeUnit](x: T; to: typedesc[U]): U =
result = quote do:
`resType`(`x`.FloatType * `scale`)
else:
error("Cannot convert " & $T & " to " & $U & " as they represent different " &
error("Cannot convert " & pretty(xCT) & " to " & pretty(yCT) & " as they represent different " &
"quantities!")

macro toDef*[T: SomeUnit](x: T, to: untyped): untyped =
Expand Down

0 comments on commit e8ee8a0

Please sign in to comment.