mirror of https://github.com/exaloop/codon.git
Add tests for super()
parent
5672cebe1c
commit
3920a16cdd
|
@ -1953,7 +1953,7 @@ ExprPtr TypecheckVisitor::transformSuper(const CallExpr *expr) {
|
||||||
if (!expr->args.empty())
|
if (!expr->args.empty())
|
||||||
error("super does not take arguments");
|
error("super does not take arguments");
|
||||||
|
|
||||||
if (ctx->bases.empty())
|
if (ctx->bases.empty() || !ctx->bases.back().type)
|
||||||
error("no parent classes available");
|
error("no parent classes available");
|
||||||
auto fptyp = ctx->bases.back().type->getFunc();
|
auto fptyp = ctx->bases.back().type->getFunc();
|
||||||
if (!fptyp || fptyp->ast->hasAttr(Attr::Method))
|
if (!fptyp || fptyp->ast->hasAttr(Attr::Method))
|
||||||
|
|
|
@ -679,3 +679,33 @@ def foo(x: Callable[[1,2], 3]): pass #! unexpected static type
|
||||||
|
|
||||||
#%% static_unify_2,barebones
|
#%% static_unify_2,barebones
|
||||||
def foo(x: List[1]): pass #! cannot unify T and 1
|
def foo(x: List[1]): pass #! cannot unify T and 1
|
||||||
|
|
||||||
|
#%% super,barebones
|
||||||
|
class A[T]:
|
||||||
|
a: T
|
||||||
|
def __init__(self, t: T):
|
||||||
|
self.a = t
|
||||||
|
def foo(self):
|
||||||
|
return f'A:{self.a}'
|
||||||
|
class B(A[str]):
|
||||||
|
b: int
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__('s')
|
||||||
|
self.b = 6
|
||||||
|
def baz(self):
|
||||||
|
return f'{super().foo()}::{self.b}'
|
||||||
|
b = B()
|
||||||
|
print b.foo() #: A:s
|
||||||
|
print b.baz() #: A:s::6
|
||||||
|
|
||||||
|
|
||||||
|
#%% super_error,barebones
|
||||||
|
class A:
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
a = A()
|
||||||
|
#! no parent classes available
|
||||||
|
#! while realizing A.__init__:1 (arguments A.__init__:1[A])
|
||||||
|
|
||||||
|
#%% super_error_2,barebones
|
||||||
|
super().foo(1) #! no parent classes available
|
||||||
|
|
Loading…
Reference in New Issue