/
constraints.scala
39 lines (38 loc) · 1.28 KB
/
constraints.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
package org.cvogt
package object constraints{
import scala.annotation.implicitNotFound
/** Verifies that From is NOT a subtype of To */
@implicitNotFound(msg =
"""
Cannot prove that
${From}
is not a subtype of
${To}"""
)
trait !<:[From, To]
/** Helper class for !<: */
trait Allow_!<:[From, To]
/** Allow any two types fo !<: */
implicit def allow_!<:[From, To]: Allow_!<:[From, To] = null
/** Creates an ambigious implicit for From <: To to prevent that case. */
implicit def disallow_!<:[From, To](implicit ev: From <:< To): Allow_!<:[From, To] = null
/** implicit that verifies !<: */
implicit def conforms_!<:[A,B](implicit ev: Allow_!<:[A, B]): A !<: B = null
/** Verifies that From is not identical to To */
@implicitNotFound(msg =
"""
Cannot prove that
${From}
is not identical to
${To}"""
)
trait !=:=[From, To]
/** Helper class for !=:= */
trait Allow_!=:=[From, To]
/** Allow any two types fo !=:= */
implicit def allow_!=:=[From, To]: Allow_!=:=[From, To] = null
/** Creates an ambigious implicit for From =:= To to prevent that case. */
implicit def disallow_!=:=[From, To](implicit ev: From =:= To): Allow_!=:=[From, To] = null
/** implicit that verifies !=:= */
implicit def conforms_!=:=[A,B](implicit ev: Allow_!=:=[A, B]): A !=:= B = null
}