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", () => {
|
describe("error reporting from collection functions", () => {
|
||||||
testEval("arr = [normal(3,2)]; map(arr, zarathsuzaWasHere)", "")
|
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))"
|
// FIXME: returns "Error(Function not found: map(Array,Symbol))"
|
||||||
// Actually this error is correct but not informative
|
// 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)=x; f(f)", "Ok(lambda(x=>internal code))")
|
||||||
testEvalToBe(
|
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.)",
|
"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)]) =>
|
| ("reduceReverse", [EvArray(aValueArray), initialValue, EvLambda(aLambdaValue)]) =>
|
||||||
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
|
doReduceReverseArray(aValueArray, initialValue, aLambdaValue)
|
||||||
| ("reverse", [EvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->EvArray->Ok
|
| ("reverse", [EvArray(aValueArray)]) => aValueArray->Belt.Array.reverse->EvArray->Ok
|
||||||
| (_, [EvBool(_)]) | (_, [EvNumber(_)]) | (_, [EvString(_)]) | (_, [EvBool(_), EvBool(_)]) | (_, [EvNumber(_), EvNumber(_)]) | (_, [EvString(_), EvString(_)]) => callMathJs(call)
|
| (_, [EvBool(_)])
|
||||||
| call => Error(REFunctionNotFound(call->functionCallToCallSignature->functionCallSignatureToString)) // Report full type signature as error
|
| (_, [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,
|
'e,
|
||||||
> =>
|
> =>
|
||||||
switch valueList {
|
switch valueList {
|
||||||
| list{EvCall(fName), ...args} =>
|
| list{EvCall(fName), ...args} => {
|
||||||
(fName, args->Belt.List.toArray)->BuiltIn.dispatch(environment, reduceExpression)
|
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(_)} =>
|
| list{EvLambda(_)} =>
|
||||||
|
// TODO: remove on solving issue#558
|
||||||
valueList
|
valueList
|
||||||
->Lambda.checkIfReduced
|
->Lambda.checkIfReduced
|
||||||
->Result.flatMap(reducedValueList =>
|
->Result.flatMap(reducedValueList =>
|
||||||
reducedValueList->Belt.List.toArray->ExpressionValue.EvArray->Ok
|
reducedValueList->Belt.List.toArray->ExpressionValue.EvArray->Ok
|
||||||
)
|
)
|
||||||
| list{EvLambda(lamdaCall), ...args} =>
|
| list{EvLambda(lamdaCall), ...args} =>
|
||||||
Lambda.doLambdaCall(lamdaCall, args, environment, reduceExpression)
|
args
|
||||||
|
->Lambda.checkIfReduced
|
||||||
|
->Result.flatMap(checkedArgs =>
|
||||||
|
Lambda.doLambdaCall(lamdaCall, checkedArgs, environment, reduceExpression)
|
||||||
|
)
|
||||||
|
|
||||||
| _ =>
|
| _ =>
|
||||||
valueList
|
valueList
|
||||||
->Lambda.checkIfReduced
|
->Lambda.checkIfReduced
|
||||||
|
|
|
@ -118,9 +118,11 @@ type expresionValueType =
|
||||||
| EvtSymbol
|
| EvtSymbol
|
||||||
|
|
||||||
type functionCallSignature = CallSignature(string, array<expresionValueType>)
|
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
|
| EvArray(_) => EvtArray
|
||||||
| EvArrayString(_) => EvtArray
|
| EvArrayString(_) => EvtArray
|
||||||
| EvBool(_) => EvtBool
|
| EvBool(_) => EvtBool
|
||||||
|
@ -130,11 +132,13 @@ let valueToValueType = (value) => switch value {
|
||||||
| EvNumber(_) => EvtNumber
|
| EvNumber(_) => EvtNumber
|
||||||
| EvRecord(_) => EvtRecord
|
| EvRecord(_) => EvtRecord
|
||||||
| EvString(_) => EvtArray
|
| EvString(_) => EvtArray
|
||||||
| EvSymbol(_) => EvtSymbol}
|
| EvSymbol(_) => EvtSymbol
|
||||||
|
}
|
||||||
|
|
||||||
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
|
let functionCallToCallSignature = (functionCall: functionCall): functionCallSignature => {
|
||||||
let (fn, args) = functionCall
|
let (fn, args) = functionCall
|
||||||
CallSignature(fn, args->Js.Array2.map(valueToValueType))}
|
CallSignature(fn, args->Js.Array2.map(valueToValueType))
|
||||||
|
}
|
||||||
|
|
||||||
let valueTypeToString = (valueType: expresionValueType): string =>
|
let valueTypeToString = (valueType: expresionValueType): string =>
|
||||||
switch valueType {
|
switch valueType {
|
||||||
|
@ -152,4 +156,5 @@ let valueTypeToString = (valueType: expresionValueType): string =>
|
||||||
|
|
||||||
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {
|
let functionCallSignatureToString = (functionCallSignature: functionCallSignature): string => {
|
||||||
let CallSignature(fn, args) = functionCallSignature
|
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