@@ -4,6 +4,7 @@ import quoted._
4
4
import quoted .matching ._
5
5
import internal .Chars .digit2int
6
6
import annotation .internal .sharable
7
+ import annotation .implicitNotFound
7
8
8
9
/** A typeclass for types that admit numeric literals.
9
10
*/
@@ -27,6 +28,7 @@ object FromDigits {
27
28
/** A subclass of `FromDigits` that also allows to convert whole number literals
28
29
* with a radix other than 10
29
30
*/
31
+ @ implicitNotFound(" Type ${T} does not have a FromDigits instance for whole numbers with radix other than 10." )
30
32
trait WithRadix [T ] extends FromDigits [T ] {
31
33
def fromDigits (digits : String ): T = fromDigits(digits, 10 )
32
34
@@ -39,36 +41,23 @@ object FromDigits {
39
41
/** A subclass of `FromDigits` that also allows to convert number
40
42
* literals containing a decimal point ".".
41
43
*/
44
+ @ implicitNotFound(" Type ${T} does not have a FromDigits instance for numbers with a decimal point." )
42
45
trait Decimal [T ] extends FromDigits [T ]
43
46
44
47
/** A subclass of `FromDigits`that allows also to convert number
45
48
* literals containing a decimal point "." or an
46
49
* exponent `('e' | 'E')['+' | '-']digit digit*`.
47
50
*/
51
+ @ implicitNotFound(" Type ${T} does not have a FromDigits instance for floating-point numbers." )
48
52
trait Floating [T ] extends Decimal [T ]
49
53
50
54
inline def fromDigits [T ](given x : FromDigits [T ]): x.type = x
51
55
52
- inline def fromRadixDigits [T ](given x : FromDigits [T ]): x.type =
53
- $ {summonDigitsImpl[x.type , FromDigits .WithRadix [T ], T ](' x , " whole numbers with radix other than 10" )}
54
-
55
- inline def fromDecimalDigits [T ](given x : FromDigits [T ]): x.type =
56
- $ {summonDigitsImpl[x.type , FromDigits .Decimal [T ], T ](' x , " numbers with a decimal point" )}
57
-
58
- inline def fromFloatingDigits [T ](given x : FromDigits [T ]): x.type =
59
- $ {summonDigitsImpl[x.type , FromDigits .Floating [T ], T ](' x , " floating-point numbers" )}
60
-
61
- private def summonDigitsImpl [Inst <: FromDigits [T ], Expected <: FromDigits [T ], T ](x : Expr [Inst ], descriptor : String )
62
- (given qctx : QuoteContext , instance : Type [Inst ], t : Type [T ], expected : Type [Expected ]): Expr [Inst ] =
63
- import qctx .tasty .{_ , given }
64
- if typeOf[Inst ] <:< typeOf[Expected ] then
65
- x
66
- else
67
- val msg = s """ |Type ${t.show} does not have a FromDigits instance for $descriptor.
68
- | Found: ${instance.show}( ${x.show})
69
- | Expected: ${expected.show}""" .stripMargin
70
- qctx.error(msg, x)
71
- Expr .nullExpr.cast[Inst ]
56
+ inline def fromRadixDigits [T ](given x : FromDigits .WithRadix [T ]): x.type = x
57
+
58
+ inline def fromDecimalDigits [T ](given x : FromDigits .Decimal [T ]): x.type = x
59
+
60
+ inline def fromFloatingDigits [T ](given x : FromDigits .Floating [T ]): x.type = x
72
61
73
62
/** The base type for exceptions that can be thrown from
74
63
* `fromDigits` conversions
0 commit comments