Error reporting if function arguments are defined
map(arr, toSample) now correctly reports toSample not found instead of macro(Array,Symbol) not defined
This commit is contained in:
parent
2265254531
commit
949b57c426
|
@ -30,8 +30,12 @@ describe("builtin exception", () => {
|
|||
)
|
||||
})
|
||||
|
||||
Skip.describe("error reporting from collection functions", () => {
|
||||
testEval("arr = [normal(3,2)]; map(arr, zarathsuzaWasHere)", "")
|
||||
describe("error reporting from collection functions", () => {
|
||||
testEval("arr=[1,2,3]; map(arr, {|x| x*2})", "Ok([2,4,6])")
|
||||
testEval(
|
||||
"arr = [normal(3,2)]; map(arr, zarathsuzaWasHere)",
|
||||
"Error(zarathsuzaWasHere is not defined)",
|
||||
)
|
||||
// FIXME: returns "Error(Function not found: map(Array,Symbol))"
|
||||
// Actually this error is correct but not informative
|
||||
})
|
||||
|
|
|
@ -25,7 +25,7 @@ describe("Arity check", () => {
|
|||
)
|
||||
testEvalToBe("f(x)=x; f(f)", "Ok(lambda(x=>internal code))")
|
||||
testEvalToBe(
|
||||
"f(x,y)=x(y); f(z)",
|
||||
"f(x,y)=x(y); f(1)",
|
||||
"Error(2 arguments expected. Instead 1 argument(s) were passed.)",
|
||||
)
|
||||
})
|
||||
|
|
|
@ -149,8 +149,15 @@ let callInternal = (call: functionCall, environment, reducer: ExpressionT.reduce
|
|||
| ("reduceReverse", [EvArray(aValueArray), initialValue, EvLambda(aLambdaValue)]) =>
|
||||
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
|
||||
| ("reverse", [EvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->EvArray->Ok
|
||||
| (_, [EvBool(_)]) | (_, [EvNumber(_)]) | (_, [EvString(_)]) | (_, [EvBool(_), EvBool(_)]) | (_, [EvNumber(_), EvNumber(_)]) | (_, [EvString(_), EvString(_)]) => callMathJs(call)
|
||||
| call => Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error
|
||||
| (_, [EvBool(_)])
|
||||
| (_, [EvNumber(_)])
|
||||
| (_, [EvString(_)])
|
||||
| (_, [EvBool(_), EvBool(_)])
|
||||
| (_, [EvNumber(_), EvNumber(_)])
|
||||
| (_, [EvString(_), EvString(_)]) =>
|
||||
callMathJs(call)
|
||||
| call =>
|
||||
Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,17 +76,30 @@ and reduceValueList = (valueList: list<expressionValue>, environment): result<
|
|||
'e,
|
||||
> =>
|
||||
switch valueList {
|
||||
| list{EvCall(fName), ...args} =>
|
||||
(fName, args->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
|
||||
| list{EvCall(fName), ...args} => {
|
||||
let rCheckedArgs = switch fName == "$_setBindings_$" {
|
||||
| false => args->Lambda.checkIfReduced
|
||||
| true => args->Ok
|
||||
}
|
||||
|
||||
rCheckedArgs->Result.flatMap(checkedArgs =>
|
||||
(fName, checkedArgs->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
|
||||
)
|
||||
}
|
||||
| list{EvLambda(_)} =>
|
||||
// TODO: remove on solving issue#558
|
||||
valueList
|
||||
->Lambda.checkIfReduced
|
||||
->Result.flatMap(reducedValueList =>
|
||||
reducedValueList->Belt.List.toArray->ExpressionValue.EvArray->Ok
|
||||
)
|
||||
| list{EvLambda(lamdaCall), ...args} =>
|
||||
Lambda.doLambdaCall(lamdaCall, args, environment, reduceExpression)
|
||||
args
|
||||
->Lambda.checkIfReduced
|
||||
->Result.flatMap(checkedArgs =>
|
||||
Lambda.doLambdaCall(lamdaCall, checkedArgs, environment, reduceExpression)
|
||||
)
|
||||
|
||||
| _ =>
|
||||
valueList
|
||||
->Lambda.checkIfReduced
|
||||
|
|
|
@ -118,9 +118,11 @@ type expresionValueType =
|
|||
| EvtSymbol
|
||||
|
||||
type functionCallSignature = CallSignature(string, array<expresionValueType>)
|
||||
type functionDefinitionSignature = FunctionDefinitionSignature(functionCallSignature, expresionValueType)
|
||||
type functionDefinitionSignature =
|
||||
FunctionDefinitionSignature(functionCallSignature, expresionValueType)
|
||||
|
||||
let valueToValueType = (value) => switch value {
|
||||
let valueToValueType = value =>
|
||||
switch value {
|
||||
| EvArray(_) => EvtArray
|
||||
| EvArrayString(_) => EvtArray
|
||||
| EvBool(_) => EvtBool
|
||||
|
@ -130,11 +132,13 @@ let valueToValueType = (value) => switch value {
|
|||
| EvNumber(_) => EvtNumber
|
||||
| EvRecord(_) => EvtRecord
|
||||
| EvString(_) => EvtArray
|
||||
| EvSymbol(_) => EvtSymbol}
|
||||
| EvSymbol(_) => EvtSymbol
|
||||
}
|
||||
|
||||
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
|
||||
let (fn, args) = functionCall
|
||||
CallSignature(fn, args->Js.Array2.map(valueToValueType))}
|
||||
CallSignature(fn, args->Js.Array2.map(valueToValueType))
|
||||
}
|
||||
|
||||
let valueTypeToString = (valueType: expresionValueType): string =>
|
||||
switch valueType {
|
||||
|
@ -152,4 +156,5 @@ let valueTypeToString = (valueType: expresionValueType): string =>
|
|||
|
||||
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {
|
||||
let CallSignature(fn, args) = functionCallSignature
|
||||
`${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})`}
|
||||
`${fn}(${args->Js.Array2.map(valueTypeToString)->Js.Array2.toString})`
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user