mirror of
https://github.com/wren-lang/wren.git
synced 2026-01-11 22:28:45 +01:00
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:
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -1 +1,2 @@
|
||||
super.foo // expect error
|
||||
super // expect error
|
||||
|
||||
Reference in New Issue
Block a user