SciNim / Unchained

A fully type safe, compile time only units library.
https://scinim.github.io/Unchained
109 stars 0 forks source link

UFCS breaks type checking of proc arguments #2

Closed Vindaar closed 3 years ago

Vindaar commented 3 years ago

The following code should CT error:

proc E_to_γ(E: GeV): UnitLess =
  result = E.to(Joule) / (m_μ * c * c) + 1
echo 5.eV.E_to_γ()

Instead of throwing an error, it compiles and runs just fine. The argument instead of 5.eV is instead 1.GeV! To make matters worse, the result of the procedure called (which is computed correctly given a wrong value of 1.GeV) is not returned. Instead 5 is returned as a value of the expression (without any kind of unit).

It works perfectly fine using regular call syntax E_to_γ(5.eV), throws a CT error.

Is this an upstream bug or a bizarre side effect + bug of our macros?

Vindaar commented 3 years ago

Oh, this could be due to our use of dot operators and the . macro... Related: https://github.com/nim-lang/Nim/issues/17056