mirror of
https://github.com/unisonweb/unison.git
synced 2024-11-13 22:29:35 +03:00
fix off-by-two error in dataConstructorish
This commit is contained in:
parent
e534a5581c
commit
90c4fd7d67
@ -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 {
|
||||
|
@ -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
|
||||
-- ^^^^^
|
12
unison-src/tests/tictactoe0-array-oob1.u
Normal file
12
unison-src/tests/tictactoe0-array-oob1.u
Normal file
@ -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
|
17
unison-src/tests/tictactoe0-npe.u
Normal file
17
unison-src/tests/tictactoe0-npe.u
Normal file
@ -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
|
43
unison-src/tests/tictactoe0.u
Normal file
43
unison-src/tests/tictactoe0.u
Normal file
@ -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
|
@ -61,4 +61,3 @@ isWin board =
|
||||
isWin (Board X O X
|
||||
O X X
|
||||
O E X)
|
||||
|
Loading…
Reference in New Issue
Block a user