|
| 1 | +:NewParser |
| 2 | + |
| 3 | + |
| 4 | +class Foo(x) |
| 5 | +//│ Defined class Foo |
| 6 | +//│ Foo: 'x -> (Foo with {x: 'x}) |
| 7 | +//│ = [Function: Foo1] |
| 8 | + |
| 9 | + |
| 10 | +:d |
| 11 | +if 1 is 1 then 1 |
| 12 | +//│ 0. Typing term if (is (1,) (1,)) then 1 |
| 13 | +//│ | Flattened conjunctions |
| 14 | +//│ | <eq (1,) (1,)> => 1 |
| 15 | +//│ | The mutable CaseOf tree |
| 16 | +//│ | IfThenElse(eq (1,) (1,),Consequent(1),MissingCase) |
| 17 | +//│ /!!!\ Uncaught error: scala.NotImplementedError: an implementation is missing |
| 18 | +//│ at: scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) |
| 19 | +//│ at: mlscript.MutCaseOf$MissingCase$.$anonfun$toTerm$1(helpers.scala:958) |
| 20 | +//│ at: scala.Option.getOrElse(Option.scala:201) |
| 21 | +//│ at: mlscript.MutCaseOf$MissingCase$.toTerm(helpers.scala:958) |
| 22 | +//│ at: mlscript.MutCaseOf$IfThenElse.toTerm(helpers.scala:901) |
| 23 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:738) |
| 24 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 25 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 26 | +//│ at: mlscript.Typer.typeStatement(Typer.scala:376) |
| 27 | +//│ at: mlscript.DiffTests.$anonfun$new$55(DiffTests.scala:558) |
| 28 | + |
| 29 | + |
| 30 | +if f is |
| 31 | + Foo(a) then a |
| 32 | +//│ ╔══[ERROR] identifier not found: f |
| 33 | +//│ ║ l.30: if f is |
| 34 | +//│ ╙── ^ |
| 35 | +//│ res: error |
| 36 | +//│ Code generation encountered an error: |
| 37 | +//│ unresolved symbol f |
| 38 | + |
| 39 | +if f is |
| 40 | + Foo(a) then a |
| 41 | + Foo(a) then a |
| 42 | +//│ /!!!\ Uncaught error: scala.NotImplementedError: an implementation is missing |
| 43 | +//│ at: scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) |
| 44 | +//│ at: mlscript.MutCaseOf$Consequent.append(helpers.scala:953) |
| 45 | +//│ at: mlscript.MutCaseOf$Match.append(helpers.scala:916) |
| 46 | +//│ at: mlscript.MutCaseOf$.$anonfun$build$1(helpers.scala:987) |
| 47 | +//│ at: mlscript.MutCaseOf$.$anonfun$build$1$adapted(helpers.scala:987) |
| 48 | +//│ at: scala.collection.immutable.List.foreach(List.scala:333) |
| 49 | +//│ at: mlscript.MutCaseOf$.build(helpers.scala:987) |
| 50 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:735) |
| 51 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 52 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 53 | + |
| 54 | + |
| 55 | +class Bar(y, z) |
| 56 | +//│ Defined class Bar |
| 57 | +//│ Bar: ('y, 'z,) -> (Bar with {y: 'y, z: 'z}) |
| 58 | +//│ = [Function: Bar1] |
| 59 | + |
| 60 | +fun test(f) = if f is |
| 61 | + Foo(a) then a |
| 62 | + Bar(b, c) then b + c |
| 63 | +//│ test: (Bar & {y: int, z: int} | (Foo with {x: 'x})) -> (int | 'x) |
| 64 | +//│ = [Function: test] |
| 65 | + |
| 66 | + |
| 67 | +class Pair(fst, snd) |
| 68 | +//│ Defined class Pair |
| 69 | +//│ Pair: ('fst, 'snd,) -> (Pair with {fst: 'fst, snd: 'snd}) |
| 70 | +//│ = [Function: Pair1] |
| 71 | + |
| 72 | +if x is |
| 73 | + Pair(0, 0) then "zeros" |
| 74 | + Pair(1, 1) then "ones" |
| 75 | + Pair(y, 1) then x |
| 76 | +//│ /!!!\ Uncaught error: scala.NotImplementedError: an implementation is missing |
| 77 | +//│ at: scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) |
| 78 | +//│ at: mlscript.MutCaseOf$IfThenElse.append(helpers.scala:888) |
| 79 | +//│ at: mlscript.MutCaseOf$Match.append(helpers.scala:916) |
| 80 | +//│ at: mlscript.MutCaseOf$.$anonfun$build$1(helpers.scala:987) |
| 81 | +//│ at: mlscript.MutCaseOf$.$anonfun$build$1$adapted(helpers.scala:987) |
| 82 | +//│ at: scala.collection.immutable.List.foreach(List.scala:333) |
| 83 | +//│ at: mlscript.MutCaseOf$.build(helpers.scala:987) |
| 84 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:735) |
| 85 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 86 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 87 | + |
| 88 | +class Z() |
| 89 | +class O() |
| 90 | +//│ Defined class Z |
| 91 | +//│ Defined class O |
| 92 | +//│ Z: () -> Z |
| 93 | +//│ = [Function: Z1] |
| 94 | +//│ O: () -> O |
| 95 | +//│ = [Function: O1] |
| 96 | + |
| 97 | +fun foo(x) = if x is |
| 98 | + Pair(Z(), Z()) then "zeros" |
| 99 | + Pair(O(), O()) then "ones" |
| 100 | +//│ foo: (Pair & {fst: O | Z, snd: nothing}) -> ("ones" | "zeros") |
| 101 | +//│ = [Function: foo] |
| 102 | + |
| 103 | +fun foo(x) = if x is |
| 104 | + Pair(a, b) then if a is |
| 105 | + Z() then if b is |
| 106 | + Z() then "zeros" |
| 107 | + O() then if b is |
| 108 | + O() then "zeros" |
| 109 | +//│ foo: (Pair & {fst: O | Z, snd: nothing}) -> "zeros" |
| 110 | +//│ = [Function: foo1] |
| 111 | + |
| 112 | +fun foo(x) = if x is |
| 113 | + Pair(a, b) then if a is |
| 114 | + Z() then if b is |
| 115 | + Z() then "zeros" |
| 116 | + else "???" |
| 117 | + O() then if b is |
| 118 | + O() then "zeros" |
| 119 | +//│ foo: (Pair & {fst: O | Z, snd: O}) -> ("???" | "zeros") |
| 120 | +//│ = [Function: foo2] |
| 121 | + |
| 122 | +fun foo(x) = if x is |
| 123 | + Pair(a, b) then if a is |
| 124 | + Z() then if b is |
| 125 | + Z() then "zeros" |
| 126 | + else "???" |
| 127 | + O() then if b is |
| 128 | + O() then "zeros" |
| 129 | + else "???" |
| 130 | +//│ foo: (Pair & {fst: O | Z}) -> ("???" | "zeros") |
| 131 | +//│ = [Function: foo3] |
| 132 | + |
| 133 | +class S(pred) |
| 134 | +//│ Defined class S |
| 135 | +//│ S: 'pred -> (S with {pred: 'pred}) |
| 136 | +//│ = [Function: S1] |
| 137 | + |
| 138 | +fun foo(x) = if x is |
| 139 | + Pair(a, b) then if a is |
| 140 | + Z() then if b is |
| 141 | + S(x) then x |
| 142 | + else "???" |
| 143 | + O() then if b is |
| 144 | + O() then "zeros" |
| 145 | + else "???" |
| 146 | +//│ foo: (Pair & {fst: O | Z, snd: (S with {pred: 'pred}) | ~S}) -> ("???" | "zeros" | 'pred) |
| 147 | +//│ = [Function: foo4] |
| 148 | + |
| 149 | +foo(Pair(Z(), Z())) |
| 150 | +//│ res: "???" | "zeros" |
| 151 | +//│ Runtime error: |
| 152 | +//│ Error: non-exhaustive case expression |
| 153 | + |
| 154 | +fun foo(x) = if x is |
| 155 | + Pair(Z(), Z()) then "zeros" |
| 156 | + Pair(O(), O()) then "ones" |
| 157 | + Pair(y, O()) then x |
| 158 | +//│ foo: (Pair & {snd: nothing} & 'a) -> ("ones" | "zeros" | 'a) |
| 159 | +//│ = [Function: foo5] |
| 160 | + |
| 161 | + |
| 162 | +fun foo(x, y) = if x is Z() and y is O() then 0 else 1 |
| 163 | +//│ /!!!\ Uncaught error: scala.NotImplementedError: an implementation is missing |
| 164 | +//│ at: scala.Predef$.$qmark$qmark$qmark(Predef.scala:344) |
| 165 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:626) |
| 166 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 167 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 168 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:714) |
| 169 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 170 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 171 | +//│ at: mlscript.Typer.$anonfun$typeTerm$2(Typer.scala:741) |
| 172 | +//│ at: mlscript.TyperHelpers.trace(TyperHelpers.scala:30) |
| 173 | +//│ at: mlscript.Typer.typeTerm(Typer.scala:747) |
| 174 | + |
| 175 | +fun foo(x, y) = if x is |
| 176 | + Z() and y is O() then 0 else 1 |
| 177 | +//│ ╔══[PARSE ERROR] Unexpected 'else' keyword here |
| 178 | +//│ ║ l.176: Z() and y is O() then 0 else 1 |
| 179 | +//│ ╙── ^^^^ |
| 180 | +//│ foo: (Z, O,) -> 0 |
| 181 | +//│ = [Function: foo6] |
| 182 | + |
| 183 | +fun foo(x, y) = |
| 184 | + if x is |
| 185 | + Z() and y is O() then 0 |
| 186 | + else 1 |
| 187 | +//│ foo: (anything, O,) -> (0 | 1) |
| 188 | +//│ = [Function: foo7] |
| 189 | + |
0 commit comments