Look at the following code.
type Price = distinct int
converter float_to_price(x: float): Price = x.toInt.Price
let x = 3.6
let y = Price(x) # y = 3, I want to disable it
let z: Price = x # z = 4, correct
I hope I can't disable the Price(3.6) or make the Price(3.6) do as Price(3.6.toInt). How can I do? There is no need to disable the conversion as it's only done for literals anyway. This means that this does not compile:
proc takesFloat(x: float) = discard
var i = 44
takesFloat(i)
But this code compiles fine.
type Price = distinct int
var f = 3.6
var p = Price(f)
echo p # 3, rather than 4
This is what I want to avoid.
I hope I can find way to prevent the code like this:
proc Price(x: float) {.error.}
But this doesn't compile.