Rename function overload 'super' to 'superf'

pull/10/head
Ibrahim Numanagić 2022-01-07 17:27:51 -08:00
parent a32e945dc1
commit cb0a6ea443
3 changed files with 15 additions and 14 deletions

View File

@ -88,9 +88,10 @@ SimplifyVisitor::apply(Cache *cache, const StmtPtr &node, const std::string &fil
}
// Reserve the following static identifiers.
for (auto name : {"staticlen", "compile_error", "isinstance", "hasattr", "type",
"TypeVar", "Callable", "argv", "super"})
"TypeVar", "Callable", "argv", "super", "superf", "fn"})
stdlib->generateCanonicalName(name);
stdlib->add(SimplifyItem::Var, "super", "super", true);
stdlib->add(SimplifyItem::Var, "superf", "superf", true);
// This code must be placed in a preamble (these are not POD types but are
// referenced by the various preamble Function.N and Tuple.N stubs)

View File

@ -1038,15 +1038,15 @@ ExprPtr TypecheckVisitor::transformCall(CallExpr *expr, const types::TypePtr &in
seenNames.insert(i.name);
}
if (expr->expr->isId("super")) {
if (expr->expr->isId("superf")) {
if (ctx->bases.back().supers.empty())
error("no matching super methods are available");
error("no matching superf methods are available");
auto parentCls = ctx->bases.back().type->getFunc()->funcParent;
auto m =
findMatchingMethods(parentCls ? CAST(parentCls, types::ClassType) : nullptr,
ctx->bases.back().supers, expr->args);
if (m.empty())
error("no matching super methods are available");
error("no matching superf methods are available");
// LOG("found {} <- {}", ctx->bases.back().type->getFunc()->toString(),
// m[0]->toString());
ExprPtr e = N<CallExpr>(N<IdExpr>(m[0]->ast->name), expr->args);

View File

@ -299,19 +299,19 @@ def foo2(x):
foo2(1) #: 2
foo2('s') #: 1
#%% super,barebones
#%% superf,barebones
class Foo:
def foo(a):
# super(a)
# superf(a)
print 'foo-1', a
def foo(a: int):
super(a)
superf(a)
print 'foo-2', a
def foo(a: str):
super(a)
superf(a)
print 'foo-3', a
def foo(a):
super(a)
superf(a)
print 'foo-4', a
Foo.foo(1)
#: foo-1 1
@ -324,21 +324,21 @@ class Bear:
@extend
class Bear:
def woof(x):
return super(x) + f' bear w--f {x}'
return superf(x) + f' bear w--f {x}'
print Bear.woof('!')
#: bear woof ! bear w--f !
class PolarBear(Bear):
def woof():
return 'polar ' + super('@')
return 'polar ' + superf('@')
print PolarBear.woof()
#: polar bear woof @ bear w--f @
#%% super_error,barebones
#%% superf_error,barebones
class Foo:
def foo(a):
super(a)
superf(a)
print 'foo-1', a
Foo.foo(1)
#! no matching super methods are available
#! no matching superf methods are available
#! while realizing Foo.foo:0