Don't inherit metaclasses.
Also disallow super() in static methods. It won't do anything useful (it always just delegates to Class) anyway.
This commit is contained in:
+5
-8
@@ -1645,14 +1645,7 @@ static void string(Compiler* compiler, bool allowAssignment)
|
||||
// directly or indirectly contained in a method for a class.
|
||||
static bool isInsideMethod(Compiler* compiler)
|
||||
{
|
||||
// Walk up the parent chain to see if there is an enclosing method.
|
||||
while (compiler != NULL)
|
||||
{
|
||||
if (compiler->methodName != NULL) return true;
|
||||
compiler = compiler->parent;
|
||||
}
|
||||
|
||||
return false;
|
||||
return compiler->fields != NULL;
|
||||
}
|
||||
|
||||
static void new_(Compiler* compiler, bool allowAssignment)
|
||||
@@ -1676,6 +1669,10 @@ static void super_(Compiler* compiler, bool allowAssignment)
|
||||
{
|
||||
error(compiler, "Cannot use 'super' outside of a method.");
|
||||
}
|
||||
else if (compiler->isStaticMethod)
|
||||
{
|
||||
error(compiler, "Cannot use 'super' in a static method.");
|
||||
}
|
||||
|
||||
loadThis(compiler);
|
||||
|
||||
|
||||
+3
-11
@@ -72,17 +72,9 @@ ObjClass* wrenNewClass(WrenVM* vm, ObjClass* superclass, int numFields)
|
||||
PinnedObj pinned;
|
||||
pinObj(vm, (Obj*)metaclass, &pinned);
|
||||
|
||||
// The metaclass inheritance chain mirrors the class's inheritance chain
|
||||
// except that when the latter bottoms out at "Object", the metaclass one
|
||||
// bottoms out at "Class".
|
||||
if (superclass == vm->objectClass)
|
||||
{
|
||||
wrenBindSuperclass(vm, metaclass, vm->classClass);
|
||||
}
|
||||
else
|
||||
{
|
||||
wrenBindSuperclass(vm, metaclass, superclass->metaclass);
|
||||
}
|
||||
// Metaclasses always inherit Class and do not parallel the non-metaclass
|
||||
// hierarchy.
|
||||
wrenBindSuperclass(vm, metaclass, vm->classClass);
|
||||
|
||||
ObjClass* classObj = wrenNewSingleClass(vm, numFields);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user