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 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519
|
{-# LANGUAGE CPP #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
#if __GLASGOW_HASKELL__ >= 805
{-# LANGUAGE NoStarIsType #-}
#endif
{-# OPTIONS_GHC -fdefer-type-errors #-}
{-# OPTIONS_GHC -fplugin GHC.TypeLits.Normalise #-}
module ErrorTests where
import Data.Proxy
import GHC.TypeLits
#if __GLASGOW_HASKELL__ >= 904
import GHC.Types
#endif
import GHC.IO.Encoding (getLocaleEncoding, textEncodingName, utf8)
import Language.Haskell.TH (litE, stringL)
import Language.Haskell.TH.Syntax (runIO)
testProxy1 :: Proxy (x + 1) -> Proxy (2 + x)
testProxy1 = id
testProxy1Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy (x + 1) -> Proxy (2 + x)"
," Actual: Proxy (x + 1) -> Proxy (x + 1)"
]
#else
["Expected type: Proxy (x + 1) -> Proxy (2 + x)"
,"Actual type: Proxy (2 + x) -> Proxy (2 + x)"
]
#endif
type family GCD (x :: Nat) (y :: Nat) :: Nat
type instance GCD 6 8 = 2
type instance GCD 9 6 = 3
testProxy2 :: Proxy (GCD 6 8 + x) -> Proxy (x + GCD 9 6)
testProxy2 = id
testProxy2Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy (GCD 6 8 + x) -> Proxy (x + GCD 9 6)"
," Actual: Proxy (2 + x) -> Proxy (2 + x)"
]
#else
["Expected type: Proxy (GCD 6 8 + x) -> Proxy (x + GCD 9 6)"
,"Actual type: Proxy (x + 3) -> Proxy (x + 3)"
]
#endif
proxyFun3 :: Proxy (x + x + x) -> ()
proxyFun3 = const ()
testProxy3 :: Proxy 8 -> ()
testProxy3 = proxyFun3
testProxy3Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy 8 -> ()"
," Actual: Proxy ((x0 + x0) + x0) -> ()"
]
#else
["Expected type: Proxy 8 -> ()"
,"Actual type: Proxy ((x0 + x0) + x0) -> ()"
]
#endif
proxyFun4 :: Proxy ((2*y)+4) -> ()
proxyFun4 = const ()
testProxy4 :: Proxy 2 -> ()
testProxy4 = proxyFun4
testProxy4Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy 2 -> ()"
," Actual: Proxy ((2 * y0) + 4) -> ()"
]
#else
["Expected type: Proxy 2 -> ()"
,"Actual type: Proxy ((2 * y0) + 4) -> ()"
]
#endif
testProxy5 :: Proxy 7 -> ()
testProxy5 = proxyFun4
testProxy5Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy 7 -> ()"
," Actual: Proxy ((2 * y1) + 4) -> ()"
]
#else
["Expected type: Proxy 7 -> ()"
,"Actual type: Proxy ((2 * y1) + 4) -> ()"
]
#endif
proxyFun6 :: Proxy (2^k) -> Proxy (2^k)
proxyFun6 = const Proxy
testProxy6 :: Proxy 7
testProxy6 = proxyFun6 (Proxy :: Proxy 7)
testProxy6Errors =
#if __GLASGOW_HASKELL__ >= 902
["Expected: Proxy 7"
," Actual: Proxy (2 ^ k0)"
]
#elif __GLASGOW_HASKELL__ >= 900
["Expected: Proxy (2 ^ k0)"
," Actual: Proxy 7"
]
#else
["Expected type: Proxy (2 ^ k0)"
,"Actual type: Proxy 7"
]
#endif
proxyFun7 :: Proxy (2^k) -> Proxy k
proxyFun7 = const Proxy
testProxy8 :: Proxy x -> Proxy (y + x)
testProxy8 = id
testProxy8Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy x -> Proxy (y + x)"
," Actual: Proxy x -> Proxy x"
]
#else
["Expected type: Proxy x -> Proxy (y + x)"
,"Actual type: Proxy x -> Proxy x"
]
#endif
#if __GLASGOW_HASKELL__ >= 904
proxyInEq :: ((a <= b) ~ (() :: Constraint)) => Proxy (a :: Nat) -> Proxy b -> ()
#else
proxyInEq :: (a <= b) => Proxy (a :: Nat) -> Proxy b -> ()
#endif
proxyInEq _ _ = ()
proxyInEq' :: ((a <=? b) ~ 'False) => Proxy (a :: Nat) -> Proxy b -> ()
proxyInEq' _ _ = ()
testProxy9 :: Proxy (a + 1) -> Proxy a -> ()
testProxy9 = proxyInEq
testProxy9Errors =
#if __GLASGOW_HASKELL__ >= 904
["Cannot satisfy: a + 1 <= a"]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (a + 1) a) 'True 'True 'False’"
else litE $ stringL "(CmpNat (a + 1) a) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'True’"
else litE $ stringL "with 'True"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘(a + 1) <=? a’ with ‘'True’"
else litE $ stringL "Couldn't match type `(a + 1) <=? a' with 'True"
)]
#endif
testProxy10 :: Proxy (a :: Nat) -> Proxy (a + 2) -> ()
testProxy10 = proxyInEq'
testProxy10Errors =
#if __GLASGOW_HASKELL__ >= 910
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘ghc-internal-9.1001.0:GHC.Internal.Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `ghc-internal-9.1001.0:GHC.Internal.Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat a (a + 2)) True True False’"
else litE $ stringL "(CmpNat a (a + 2)) True True False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘False"
else litE $ stringL "with `False"
)
]
#elif __GLASGOW_HASKELL__ >= 906
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat a (a + 2)) True True False’"
else litE $ stringL "(CmpNat a (a + 2)) True True False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘False"
else litE $ stringL "with False"
)
]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat a (a + 2)) 'True 'True 'False’"
else litE $ stringL "(CmpNat a (a + 2)) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'False"
else litE $ stringL "with 'False"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘a <=? (a + 2)’ with ‘'False’"
else litE $ stringL "Couldn't match type `a <=? (a + 2)' with 'False"
)]
#endif
testProxy11 :: Proxy (a :: Nat) -> Proxy a -> ()
testProxy11 = proxyInEq'
testProxy11Errors =
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
#if __GLASGOW_HASKELL__ >= 910
then litE $ stringL "Couldn't match type ‘True’ with ‘False’"
else litE $ stringL "Couldn't match type `True' with `False'"
#elif __GLASGOW_HASKELL__ >= 906
then litE $ stringL "Couldn't match type ‘True’ with ‘False’"
else litE $ stringL "Couldn't match type True with False"
#else
then litE $ stringL "Couldn't match type ‘'True’ with ‘'False’"
else litE $ stringL "Couldn't match type 'True with 'False"
#endif
)]
testProxy12 :: Proxy (a + b) -> Proxy (a + c) -> ()
testProxy12 = proxyInEq
testProxy12Errors =
#if __GLASGOW_HASKELL__ >= 904
["Cannot satisfy: a + b <= a + c"]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (a + b) (a + c)) 'True 'True 'False’"
else litE $ stringL "(CmpNat (a + b) (a + c)) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'True’"
else litE $ stringL "with 'True"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘(a + b) <=? (a + c)’ with ‘'True’"
else litE $ stringL "Couldn't match type `(a + b) <=? (a + c)' with 'True"
)]
#endif
testProxy13 :: Proxy (4*a) -> Proxy (2*a) ->()
testProxy13 = proxyInEq
testProxy13Errors =
#if __GLASGOW_HASKELL__ >= 904
["Cannot satisfy: 4 * a <= 2 * a"]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (4 * a) (2 * a)) 'True 'True 'False’"
else litE $ stringL "(CmpNat (4 * a) (2 * a)) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'True’"
else litE $ stringL "with 'True"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘(4 * a) <=? (2 * a)’ with ‘'True’"
else litE $ stringL "Couldn't match type `(4 * a) <=? (2 * a)' with 'True"
)]
#endif
testProxy14 :: Proxy (2*a) -> Proxy (4*a) -> ()
testProxy14 = proxyInEq'
testProxy14Errors =
#if __GLASGOW_HASKELL__ >= 910
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘ghc-internal-9.1001.0:GHC.Internal.Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `ghc-internal-9.1001.0:GHC.Internal.Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False’"
else litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘False"
else litE $ stringL "with `False"
)
]
#elif __GLASGOW_HASKELL__ >= 906
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False’"
else litE $ stringL "(CmpNat (2 * a) (4 * a)) True True False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘False"
else litE $ stringL "with False"
)
]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat (2 * a) (4 * a)) 'True 'True 'False’"
else litE $ stringL "(CmpNat (2 * a) (4 * a)) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'False"
else litE $ stringL "with 'False"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘(2 * a) <=? (4 * a)’ with ‘'False’"
else litE $ stringL "Couldn't match type `(2 * a) <=? (4 * a)' with 'False"
)]
#endif
type family CLog (b :: Nat) (x :: Nat) :: Nat
type instance CLog 2 2 = 1
testProxy15 :: (CLog 2 (2 ^ n) ~ n, (1 <=? n) ~ True) => Proxy n -> Proxy (n+d)
testProxy15 = id
testProxy15Errors =
#if __GLASGOW_HASKELL__ >= 900
["Expected: Proxy n -> Proxy (n + d)"
," Actual: Proxy n -> Proxy n"
]
#else
["Expected type: Proxy n -> Proxy (n + d)"
,"Actual type: Proxy n -> Proxy n"
]
#endif
data Fin (n :: Nat) where
FZ :: Fin (n + 1)
FS :: Fin n -> Fin (n + 1)
test16 :: forall n . Integer -> Fin n
test16 n = case n of
0 -> FZ
x -> FS (test16 @(n-1) (x-1))
test16Errors =
#if __GLASGOW_HASKELL__ >= 904
["Cannot satisfy: 1 <= n"]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat 1 n) 'True 'True 'False’"
else litE $ stringL "(CmpNat 1 n) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'True’"
else litE $ stringL "with 'True"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘1 <=? n’ with ‘'True’"
else litE $ stringL "Couldn't match type `1 <=? n' with 'True"
)]
#endif
data Dict c where
Dict :: c => Dict c
deriving instance Show (Dict c)
data Boo (n :: Nat) = Boo
test17 :: Show (Boo n) => Proxy n -> Boo (n - 1 + 1) -> String
test17 = const show
testProxy17 :: String
testProxy17 = test17 (Proxy :: Proxy 17) Boo
test17Errors = test16Errors
#if __GLASGOW_HASKELL__ >= 904
test19f :: ((1 <= n) ~ (() :: Constraint))
#else
test19f :: (1 <= n)
#endif
=> Proxy n -> Proxy n
test19f = id
testProxy19 :: (1 <= m, m <= rp)
=> Proxy m
-> Proxy rp
-> Proxy (rp - m)
-> Proxy (rp - m)
testProxy19 _ _ = test19f
test19Errors =
#if __GLASGOW_HASKELL__ >= 904
[ "Cannot satisfy: 1 <= rp - m" ]
#elif __GLASGOW_HASKELL__ >= 902
[ "Could not deduce: Data.Type.Ord.OrdCond"
, "(CmpNat 1 (rp - m)) 'True 'True 'False"
, "~ 'True"
]
#else
["Could not deduce: (1 <=? (rp - m)) ~ 'True"]
#endif
testProxy20 :: Proxy 1 -> Proxy (m ^ 2) -> ()
testProxy20 = proxyInEq
testProxy20Errors =
#if __GLASGOW_HASKELL__ >= 904
["Cannot satisfy: 1 <= m ^ 2"]
#elif __GLASGOW_HASKELL__ >= 902
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘Data.Type.Ord.OrdCond"
else litE $ stringL "Couldn't match type `Data.Type.Ord.OrdCond"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "(CmpNat 1 (m ^ 2)) 'True 'True 'False’"
else litE $ stringL "(CmpNat 1 (m ^ 2)) 'True 'True 'False'"
)
,$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "with ‘'True’"
else litE $ stringL "with 'True"
)
]
#else
[$(do localeEncoding <- runIO (getLocaleEncoding)
if textEncodingName localeEncoding == textEncodingName utf8
then litE $ stringL "Couldn't match type ‘1 <=? (m ^ 2)’ with ‘'True’"
else litE $ stringL "Couldn't match type `1 <=? (m ^ 2)' with 'True"
)]
#endif
|