louise
The Louise language: compiler, runtime, std, tooling
Clone avec HTTPS, un jeton personnel en mot de passe, ou avec SSH, une clé ajoutée dans vos paramètres.
Dernier runRéussi#125 · main · 16 min 13 s
0Étoiles
0Forks
40Issues
| 1 | // Inference and the exhaustiveness checker each match a refined |
| 2 | // constructor's index against the scrutinee's type, in a walk of their |
| 3 | // own (issue #240). On a match's first arm they must agree: a constructor |
| 4 | // inference refuses (E0202) is one the checker finds impossible (W0301), |
| 5 | // and one inference accepts is one the checker keeps. If the checker |
| 6 | // dropped a constructor inference accepts, a missing arm for it would go |
| 7 | // unreported. Each case is one shape where the two walks differ. |
| 8 | |
| 9 | pub type Ix<a> |
| 10 | { OfInt(Int) -> Ix<Int> |
| 11 | , OfBool(Bool) -> Ix<Bool> |
| 12 | , OfList(Int) -> Ix<List<Int>> |
| 13 | , OfPair(Int) -> Ix<(Int, Bool)> |
| 14 | , Any(Int) -> Ix<a> |
| 15 | } |
| 16 | |
| 17 | pub type Two<a, b> { Same(Int) -> Two<c, c>, Apart(Int) -> Two<Int, Bool> } |
| 18 | |
| 19 | pub fn concrete_refused :: x: Ix<Int> -> Int |
| 20 | { |
| 21 | match x { OfBool(_) -> 1, _ -> 0 } //~ ERROR E0202 cannot match |
| 22 | //~^ WARN W0301 |
| 23 | } |
| 24 | |
| 25 | pub fn concrete_kept :: x: Ix<Int> -> Int |
| 26 | { |
| 27 | match x { OfInt(_) -> 1, _ -> 0 } |
| 28 | } |
| 29 | |
| 30 | pub fn rigid_kept :: x: Ix<a> -> Int |
| 31 | { |
| 32 | match x { OfBool(_) -> 1, _ -> 0 } |
| 33 | } |
| 34 | |
| 35 | pub fn nested_refused :: x: Ix<List<Bool>> -> Int |
| 36 | { |
| 37 | match x { OfList(_) -> 1, _ -> 0 } //~ ERROR E0202 cannot match |
| 38 | //~^ WARN W0301 |
| 39 | } |
| 40 | |
| 41 | pub fn nested_rigid_kept :: x: Ix<List<a>> -> Int |
| 42 | { |
| 43 | match x { OfList(_) -> 1, _ -> 0 } |
| 44 | } |
| 45 | |
| 46 | pub fn tuple_refused :: x: Ix<(Int, Int)> -> Int |
| 47 | { |
| 48 | match x { OfPair(_) -> 1, _ -> 0 } //~ ERROR E0202 cannot match |
| 49 | //~^ WARN W0301 |
| 50 | } |
| 51 | |
| 52 | pub fn tuple_rigid_kept :: x: Ix<(a, b)> -> Int |
| 53 | { |
| 54 | match x { OfPair(_) -> 1, _ -> 0 } |
| 55 | } |
| 56 | |
| 57 | pub fn unrefined_kept :: x: Ix<Bool> -> Int |
| 58 | { |
| 59 | match x { Any(_) -> 1, _ -> 0 } |
| 60 | } |
| 61 | |
| 62 | pub fn repeated_refused :: x: Two<Int, Bool> -> Int |
| 63 | { |
| 64 | match x { Same(_) -> 1, _ -> 0 } //~ ERROR E0202 cannot match |
| 65 | //~^ WARN W0301 |
| 66 | } |
| 67 | |
| 68 | // `Apart` is impossible here, so `Same` alone covers every value. |
| 69 | pub fn repeated_concrete_kept :: x: Two<Int, Int> -> Int |
| 70 | { |
| 71 | match x { Same(_) -> 1 } |
| 72 | } |
| 73 | |
| 74 | pub fn repeated_rigid_kept :: x: Two<p, q> -> Int |
| 75 | { |
| 76 | match x { Same(_) -> 1, _ -> 0 } |
| 77 | } |