Skip to content

Commit ec3fa6b

Browse files
committed
[[ Script ]] Implemented NoMatchingHandlerError (still to resolve handler names correctly).
1 parent aa805e0 commit ec3fa6b

File tree

3 files changed

+37
-20
lines changed

3 files changed

+37
-20
lines changed

libscript/src/script-instance.cpp

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ bool MCScriptThrowInvalidValueForParameterError(MCScriptModuleRef module, MCName
156156

157157
bool MCScriptThrowInvalidValueForResultError(MCScriptModuleRef p_module, MCScriptDefinition *p_handler, MCTypeInfoRef p_expected_type, MCValueRef p_value)
158158
{
159-
return MCErrorCreateAndThrow(kMCScriptInvalidReturnValueErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), "type", p_expected_type, "value", p_value, nil);
159+
return MCErrorCreateAndThrow(kMCScriptInvalidReturnValueErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), "type", MCNamedTypeInfoGetName(p_expected_type), "value", p_value, nil);
160160
}
161161

162162
bool MCScriptThrowInParameterNotDefinedError(MCScriptModuleRef p_module, MCScriptDefinition *p_handler, uindex_t p_index)
@@ -181,12 +181,12 @@ bool MCScriptThrowGlobalVariableUsedBeforeDefinedError(MCScriptModuleRef p_modul
181181

182182
bool MCScriptThrowInvalidValueForLocalVariableError(MCScriptModuleRef p_module, MCScriptDefinition *p_handler, uindex_t p_index, MCTypeInfoRef p_expected_type, MCValueRef p_value)
183183
{
184-
return MCErrorCreateAndThrow(kMCScriptInvalidVariableValueErrorTypeInfo, "module", p_module -> name, p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), "variable", MCScriptGetNameOfLocalVariableInModule(p_module, p_handler, p_index), "type", p_expected_type, "value", p_value, nil);
184+
return MCErrorCreateAndThrow(kMCScriptInvalidVariableValueErrorTypeInfo, "module", p_module -> name, p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_handler), "variable", MCScriptGetNameOfLocalVariableInModule(p_module, p_handler, p_index), "type", MCNamedTypeInfoGetName(p_expected_type), "value", p_value, nil);
185185
}
186186

187187
bool MCScriptThrowInvalidValueForGlobalVariableError(MCScriptModuleRef p_module, uindex_t p_index, MCTypeInfoRef p_expected_type, MCValueRef p_value)
188188
{
189-
return MCErrorCreateAndThrow(kMCScriptInvalidVariableValueErrorTypeInfo, "module", p_module -> name, p_module -> name, "variable", MCScriptGetNameOfGlobalVariableInModule(p_module, p_index), "type", p_expected_type, "value", p_value, nil);
189+
return MCErrorCreateAndThrow(kMCScriptInvalidVariableValueErrorTypeInfo, "module", p_module -> name, p_module -> name, "variable", MCScriptGetNameOfGlobalVariableInModule(p_module, p_index), "type", MCNamedTypeInfoGetName(p_expected_type), "value", p_value, nil);
190190
}
191191

192192
bool MCScriptThrowNotABooleanError(MCValueRef p_value)
@@ -202,7 +202,7 @@ bool MCScriptThrowWrongNumberOfArgumentsForInvokeError(MCScriptModuleRef p_modul
202202

203203
bool MCScriptThrowInvalidValueForArgumentError(MCScriptModuleRef p_module, MCScriptDefinition *p_definition, uindex_t p_arg_index, MCTypeInfoRef p_expected_type, MCValueRef p_value)
204204
{
205-
return MCErrorCreateAndThrow(kMCScriptInvalidArgumentValueErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_definition), MCScriptGetNameOfParameterInModule(p_module, p_definition, p_arg_index), "type", p_expected_type, "value", p_value, nil);
205+
return MCErrorCreateAndThrow(kMCScriptInvalidArgumentValueErrorTypeInfo, "module", p_module -> name, "handler", MCScriptGetNameOfDefinitionInModule(p_module, p_definition), "parameter", MCScriptGetNameOfParameterInModule(p_module, p_definition, p_arg_index), "type", MCNamedTypeInfoGetName(p_expected_type), "value", p_value, nil);
206206
}
207207

208208
bool MCScriptThrowUnableToResolveForeignHandlerError(MCScriptModuleRef p_module, MCScriptDefinition *p_definition)
@@ -212,26 +212,40 @@ bool MCScriptThrowUnableToResolveForeignHandlerError(MCScriptModuleRef p_module,
212212

213213
bool MCScriptThrowUnableToResolveTypeError(MCTypeInfoRef p_type)
214214
{
215-
return MCErrorCreateAndThrow(kMCScriptTypeBindingErrorTypeInfo, "type", p_type, nil);
215+
return MCErrorCreateAndThrow(kMCScriptTypeBindingErrorTypeInfo, "type", MCNamedTypeInfoGetName(p_type), nil);
216216
}
217217

218218
bool MCScriptThrowUnableToResolveMultiInvoke(MCScriptModuleRef p_module, MCScriptDefinition *p_definition, MCProperListRef p_arguments)
219219
{
220-
MCAutoProperListRef t_handlers;
221-
if (!MCProperListCreateMutable(&t_handlers))
220+
MCAutoListRef t_handlers;
221+
if (!MCListCreateMutable(',', &t_handlers))
222222
return false;
223223

224-
MCScriptDefinitionGroupDefinition *t_group;
224+
/* MCScriptDefinitionGroupDefinition *t_group;
225225
t_group = static_cast<MCScriptDefinitionGroupDefinition *>(p_definition);
226226
for(uindex_t i = 0; i < t_group -> handler_count; i++)
227227
{
228+
// TODO: Resolve definitions correctly.
228229
MCNameRef t_name;
229230
t_name = MCScriptGetNameOfDefinitionInModule(p_module, p_module -> definitions[i]);
230-
if (!MCProperListPushElementOntoBack(*t_handlers, t_name))
231+
if (!MCListAppend(*t_handlers, t_name))
231232
return false;
232-
}
233+
} */
234+
235+
MCAutoListRef t_types;
236+
if (!MCListCreateMutable(',', &t_types))
237+
return false;
238+
239+
for(uindex_t i = 0; i < MCProperListGetLength(p_arguments); i++)
240+
if (!MCListAppend(*t_types, MCNamedTypeInfoGetName(MCValueGetTypeInfo(MCProperListFetchElementAtIndex(p_arguments, i)))))
241+
return false;
242+
243+
MCAutoStringRef t_handler_list, t_type_list;
244+
if (!MCListCopyAsString(*t_handlers, &t_handler_list) ||
245+
!MCListCopyAsString(*t_types, &t_type_list))
246+
return false;
233247

234-
return MCErrorCreateAndThrow(nil);
248+
return MCErrorCreateAndThrow(kMCScriptNoMatchingHandlerErrorTypeInfo, "handlers", *t_handler_list, "types", *t_type_list, nil);
235249
}
236250

237251
///////////

libscript/src/script-object.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ MCTypeInfoRef kMCScriptWrongNumberOfArgumentsErrorTypeInfo;
1616
MCTypeInfoRef kMCScriptForeignHandlerBindingErrorTypeInfo;
1717
MCTypeInfoRef kMCScriptMultiInvokeBindingErrorTypeInfo;
1818
MCTypeInfoRef kMCScriptTypeBindingErrorTypeInfo;
19+
MCTypeInfoRef kMCScriptNoMatchingHandlerErrorTypeInfo;
1920

2021
////////////////////////////////////////////////////////////////////////////////
2122

@@ -233,17 +234,18 @@ bool MCScriptInitialize(void)
233234

234235
// This block creates all the default errors
235236
{
236-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.InParameterNotDefinedError"), MCSTR("In parameters must be defined before calling"), kMCScriptInParameterNotDefinedErrorTypeInfo);
237-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.OutParameterNotDefinedError"), MCSTR("Out parameters must be defined before returning"), kMCScriptOutParameterNotDefinedErrorTypeInfo);
238-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.VariableUsedBeforeDefinedError"), MCSTR("Variables must be defined before being used"), kMCScriptVariableUsedBeforeDefinedErrorTypeInfo);
239-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ReturnValueTypeError"), MCSTR("Value is not of correct type for return"), kMCScriptInvalidReturnValueErrorTypeInfo);
240-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.VariableValueTypeError"), MCSTR("Value is not of correct type for assignment to variable"), kMCScriptInvalidVariableValueErrorTypeInfo);
241-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ArgumentValueTypeError"), MCSTR("Value is not of correct type for passing as argument"), kMCScriptInvalidArgumentValueErrorTypeInfo);
237+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.InParameterNotDefinedError"), MCSTR("In parameters must be defined before calling - parameter %{parameter} of %{module}.%{handler}"), kMCScriptInParameterNotDefinedErrorTypeInfo);
238+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.OutParameterNotDefinedError"), MCSTR("Out parameters must be defined before returning - parameter %{parameter} of %{module}.%{handler}"), kMCScriptOutParameterNotDefinedErrorTypeInfo);
239+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.VariableUsedBeforeDefinedError"), MCSTR("Variables must be defined before being used - variable %{variable} in %{module}.%{handler}"), kMCScriptVariableUsedBeforeDefinedErrorTypeInfo);
240+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ReturnValueTypeError"), MCSTR("Value is not of correct type for return - expected type %{type} when returning from %{module}.%{handler}"), kMCScriptInvalidReturnValueErrorTypeInfo);
241+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.VariableValueTypeError"), MCSTR("Value is not of correct type for assignment to variable - expected type %{type} for assigning to variable %{variable} in %{module}.%{handler}"), kMCScriptInvalidVariableValueErrorTypeInfo);
242+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ArgumentValueTypeError"), MCSTR("Value is not of correct type for passing as argument - expected type %{type} for passing to parameter %{parameter} of %{module}.%{handler}"), kMCScriptInvalidArgumentValueErrorTypeInfo);
242243
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.NotABooleanValueError"), MCSTR("Value is not a boolean"), kMCScriptNotABooleanValueErrorTypeInfo);
243-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.WrongNumberOfArgumentsError"), MCSTR("Wrong number of arguments passed to handler"), kMCScriptWrongNumberOfArgumentsErrorTypeInfo);
244-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ForeignHandlerBindingError"), MCSTR("Unable to bind foreign handler"), kMCScriptForeignHandlerBindingErrorTypeInfo);
244+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.WrongNumberOfArgumentsError"), MCSTR("Wrong number of arguments passed to handler %{module}.%{handler}"), kMCScriptWrongNumberOfArgumentsErrorTypeInfo);
245+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.ForeignHandlerBindingError"), MCSTR("Unable to bind foreign handler %{module}.%{handler}"), kMCScriptForeignHandlerBindingErrorTypeInfo);
245246
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.PolymorphicHandlerBindingError"), MCSTR("Unable to bind appropriate handler"), kMCScriptMultiInvokeBindingErrorTypeInfo);
246-
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.TypeBindingError"), MCSTR("Attempt to use an unbound named type"), kMCScriptTypeBindingErrorTypeInfo);
247+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.TypeBindingError"), MCSTR("Attempt to use unbound named type %{type}"), kMCScriptTypeBindingErrorTypeInfo);
248+
MCScriptCreateNamedErrorType(MCNAME("livecode.lang.NoMatchingHandlerError"), MCSTR("No matching handler for arguments with types (%{types}) - possible handlers (%{handlers})"), kMCScriptNoMatchingHandlerErrorTypeInfo);
247249
}
248250

249251
return true;

libscript/src/script-private.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ extern MCTypeInfoRef kMCScriptWrongNumberOfArgumentsErrorTypeInfo;
2121
extern MCTypeInfoRef kMCScriptForeignHandlerBindingErrorTypeInfo;
2222
extern MCTypeInfoRef kMCScriptMultiInvokeBindingErrorTypeInfo;
2323
extern MCTypeInfoRef kMCScriptTypeBindingErrorTypeInfo;
24+
extern MCTypeInfoRef kMCScriptNoMatchingHandlerErrorTypeInfo;
2425

2526
////////////////////////////////////////////////////////////////////////////////
2627

0 commit comments

Comments
 (0)