diff --git a/runtime-jvm/main/src/main/scala/BuiltinTypes.scala b/runtime-jvm/main/src/main/scala/BuiltinTypes.scala index 1667133a1..01041ed95 100644 --- a/runtime-jvm/main/src/main/scala/BuiltinTypes.scala +++ b/runtime-jvm/main/src/main/scala/BuiltinTypes.scala @@ -95,7 +95,7 @@ object BuiltinTypes { } } - def dataConstructorish(req: (Array[Value]) => Value, decompile: Term, + def dataConstructorish(req: Array[Value] => Value, decompile: Term, paramNames: Name*): Computation = { val arity = paramNames.length val body: Computation = arity match { @@ -119,7 +119,7 @@ object BuiltinTypes { (r,rec,top,stackU,x1,x0,stackB,x1b,x0b) => { // arity = 3, argsStart = top.toInt, argsStop = top.toInt + 1 // arity = 4, argsStart = top.toInt - 1, argsStop = top.toInt + 1 - val argsStart = top.toInt - ((arity - compilation.K) + 1) + val argsStart = top.toInt + 1 - (arity - compilation.K) val argsStop = top.toInt + 1 val args = new Array[Value](arity) locally { diff --git a/unison-src/errors/poor-error-message/overapplied-data-constructor-loc.u b/unison-src/errors/poor-error-message/overapplied-data-constructor-loc.u new file mode 100644 index 000000000..b45cd5c36 --- /dev/null +++ b/unison-src/errors/poor-error-message/overapplied-data-constructor-loc.u @@ -0,0 +1,17 @@ +-- board piece +type P = X | O | E + +type Board = Board P P + +use Board.Board +use P O X E + +case Board X O X + of Board a b c -> a + + +-- gives this error: + -- This looks like a function call, but with a Board where the function should be. Are you missing an operator? + -- ^^^^^ + -- 13 | case Board X O X + -- ^^^^^ diff --git a/unison-src/tests/tictactoe.uu b/unison-src/tests/tictactoe.u similarity index 100% rename from unison-src/tests/tictactoe.uu rename to unison-src/tests/tictactoe.u diff --git a/unison-src/tests/tictactoe0-array-oob1.u b/unison-src/tests/tictactoe0-array-oob1.u new file mode 100644 index 000000000..462544dc9 --- /dev/null +++ b/unison-src/tests/tictactoe0-array-oob1.u @@ -0,0 +1,12 @@ +-- board piece + +type Board = Board UInt64 UInt64 UInt64 + +use Board.Board + +-- uncommenting these gives errors from NPE to array index out of bounds -1, -2 +-- x = 1 +-- y = 2 + +case Board 77 88 99 + of Board a b c -> c diff --git a/unison-src/tests/tictactoe0-npe.u b/unison-src/tests/tictactoe0-npe.u new file mode 100644 index 000000000..a39e1280c --- /dev/null +++ b/unison-src/tests/tictactoe0-npe.u @@ -0,0 +1,17 @@ +-- board piece +type P = X | O | E + +type Board = Board P P P P P P P P P + +use Board.Board +use P O X E + +whatevs a b c = a + +b = Board X O X O X X O E X +x = 1 +y = 2 +z = 3 + +case b of + Board a b c d e f g h i -> a diff --git a/unison-src/tests/tictactoe0.u b/unison-src/tests/tictactoe0.u new file mode 100644 index 000000000..3af01038b --- /dev/null +++ b/unison-src/tests/tictactoe0.u @@ -0,0 +1,43 @@ +-- board piece +type P = X | O | E + +type Board = Board P P P P P P P P P + +use Board Board +use P O X E +use Optional Some None + +orElse a b = + case a of + None -> b + a -> a + +namespace P where + (/=) : P -> P -> Boolean + a /= b = not (a == b) + (==) : P -> P -> Boolean + a == b = case (a,b) of + (X,X) -> true + (O,O) -> true + _ -> false + + +b = (Board X O X + O X X + O E X) + +isWin board = + same : P -> P -> P -> Optional P + same a b c = if and (and (a P.== b) (a P.== c)) (a P./= E) + then Some a + else None + case board of + -- vertical top/center/bottom + -- horizontal left/center/right + -- diagonal rising/falling + Board a b c + d e f + g h i -> (same a b c) + +isWin b +-- Some 3 diff --git a/unison-src/tests/tictactoe2.uu b/unison-src/tests/tictactoe2.u similarity index 99% rename from unison-src/tests/tictactoe2.uu rename to unison-src/tests/tictactoe2.u index d29720d85..e6df64228 100644 --- a/unison-src/tests/tictactoe2.uu +++ b/unison-src/tests/tictactoe2.u @@ -61,4 +61,3 @@ isWin board = isWin (Board X O X O X X O E X) -