contracts.coffee
contracts.coffee copied to clipboard
Object and function contracts conflicts when used in OR
Object and function contracts conflicts when used in OR. Both tests should pass.
TFunc = ? (Any?) -> Any?
TSignalData = ? TFunc or {
foo: Any
bar: Any
}
a :: (TSignalData) -> Any
a = (b) ->
# test
a ->
a foo: 1, bar: 2
So there are actually two problems here :)
First, the or in TSignalData is being treated as a normal logical or (ie ||) instead of the contract combinator or. This is basically the same bug as in #38.
But, even if there wasn't a bug this still isn't a valid contract. The problem is you can't have two "higher-order" contracts in an or. Since both the function and the object have delayed behavior, there's no way to check them both. So we have to disallow more than one higher-order contract in an or combinator.
So when the #38 bug is fixed you'll get an error message saying "Error: Cannot have more than 1 higher order contract in 'or'" which is correct.
Wait...what I said was wrong. Turns out we actually can and should allow a function and an object in an or combinator. Easy to distinguish the cases by typeof. Where it falls apart is multiple higher-order functions which we still can't allow.