Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions src/classes/metafunction.c
Original file line number Diff line number Diff line change
Expand Up @@ -1175,6 +1175,14 @@ static bool mfcompiler_emitresolver(mfcompiler *compiler, int nresolutions, mfco
exactpath.knownarity = resolutions[0].nparams;
exactpath.aritychecked = true;
path = &exactpath;

// Add a sparse to verify that nargs matches the known arity
mfindx deflt;
mfcompiler_emitfail(compiler, &deflt);
mfcompilersparseentry correctarity;
correctarity.value = path->knownarity;
ERR_CHECK_RETURN(mfcompiler_emitresolver(compiler, nresolutions, resolutions, path, &correctarity.target));
return mfcompiler_emitsparse(compiler, 1, &correctarity, deflt, entry);
}

/* For exact arity without typed params, emit the lone fixed-arity winner. */
Expand Down Expand Up @@ -1298,7 +1306,7 @@ void metafunction_disassemble(objectmetafunction *fn) {
static bool metafunction_runresolver(objectmetafunction *fn, int nargs, value *args, error *err, value *out) {
mfinstruction *instructions = fn->resolver.data;
if (!instructions) return metafunction_resolveslow(fn, nargs, args, err, out);

mfindx pc = fn->entry;
int reg = nargs; // Single register initialized with nargs

Expand All @@ -1307,7 +1315,7 @@ static bool metafunction_runresolver(objectmetafunction *fn, int nargs, value *a
case MFOP_SLOW:
return metafunction_resolveslow(fn, nargs, args, err, out);
case MFOP_RESOLVE: {
pc++; *out=fn->fns.data[instructions[pc]];
*out=fn->fns.data[instructions[++pc]];
return true;
}
case MFOP_FAIL:
Expand Down
2 changes: 1 addition & 1 deletion test/matrix/identity.morpho
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,4 @@ print a
// expect: [ 0 0 1 ]

a = IdentityMatrix()
// expect error 'MtrxIdnttyCns'
// expect error 'MltplDsptchFld'
3 changes: 3 additions & 0 deletions test/string/err_split_args2.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

print "Hello world".split(2)
// expect error 'MltplDsptchFld'
4 changes: 4 additions & 0 deletions test/string/err_split_args3.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// You can not add extra arguments to a function

print "Hello world".split(" ", 2)
// expect error 'MltplDsptchFld'
5 changes: 5 additions & 0 deletions test/string/err_split_args4.morpho
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
print "Hello world".split(" ")
// expect: [ Hello, world ]

print "Hello world".split()
// expect error 'MltplDsptchFld'
Loading