Segfault when calling super at top-level with no arguments.

If enclosingClass is null, we can't proceed with compilation since we don't have its name.
This commit is contained in:
Kyle Marek-Spartz
2015-01-09 15:14:06 -06:00
parent aa48223361
commit 3490c8d2f3
2 changed files with 20 additions and 19 deletions

View File

@ -1835,28 +1835,28 @@ static void super_(Compiler* compiler, bool allowAssignment)
else if (enclosingClass->isStaticMethod)
{
error(compiler, "Cannot use 'super' in a static method.");
}
} else {
loadThis(compiler);
loadThis(compiler);
// TODO: Super operator calls.
// TODO: Super operator calls.
// See if it's a named super call, or an unnamed one.
if (match(compiler, TOKEN_DOT))
{
// Compile the superclass call.
consume(compiler, TOKEN_NAME, "Expect method name after 'super.'.");
namedCall(compiler, allowAssignment, CODE_SUPER_0);
}
else
{
// No explicit name, so use the name of the enclosing method.
char name[MAX_METHOD_SIGNATURE];
int length = enclosingClass->methodLength;
strncpy(name, enclosingClass->methodName, length);
// See if it's a named super call, or an unnamed one.
if (match(compiler, TOKEN_DOT))
{
// Compile the superclass call.
consume(compiler, TOKEN_NAME, "Expect method name after 'super.'.");
namedCall(compiler, allowAssignment, CODE_SUPER_0);
}
else
{
// No explicit name, so use the name of the enclosing method.
char name[MAX_METHOD_SIGNATURE];
int length = enclosingClass->methodLength;
strncpy(name, enclosingClass->methodName, length);
// Call the superclass method with the same name.
methodCall(compiler, CODE_SUPER_0, name, length);
// Call the superclass method with the same name.
methodCall(compiler, CODE_SUPER_0, name, length);
}
}
}

View File

@ -1 +1,2 @@
super.foo // expect error
super // expect error