diff --git a/codon/parser/visitors/typecheck/typecheck_expr.cpp b/codon/parser/visitors/typecheck/typecheck_expr.cpp index 0213aaa9..3ea805c2 100644 --- a/codon/parser/visitors/typecheck/typecheck_expr.cpp +++ b/codon/parser/visitors/typecheck/typecheck_expr.cpp @@ -1953,7 +1953,7 @@ ExprPtr TypecheckVisitor::transformSuper(const CallExpr *expr) { if (!expr->args.empty()) error("super does not take arguments"); - if (ctx->bases.empty()) + if (ctx->bases.empty() || !ctx->bases.back().type) error("no parent classes available"); auto fptyp = ctx->bases.back().type->getFunc(); if (!fptyp || fptyp->ast->hasAttr(Attr::Method)) diff --git a/test/parser/typecheck_expr.codon b/test/parser/typecheck_expr.codon index ce02e25b..d2c99d1a 100644 --- a/test/parser/typecheck_expr.codon +++ b/test/parser/typecheck_expr.codon @@ -679,3 +679,33 @@ def foo(x: Callable[[1,2], 3]): pass #! unexpected static type #%% static_unify_2,barebones 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