Typechecker rejects callable argument in virtual method call
Author: BI71317Created Aug 26, 2026Updated Aug 28, 2026
The compiler fails to typecheck this program:
class A:
def f(self, block: CallableTrait[[], bool]):
return False
class B(A):
def f(self, block: CallableTrait[[], bool]):
return block()
def make_base() -> A:
return B()
print(make_base().f(lambda: False or True))
print(make_base().f(lambda: True and False))B inherits from A. The function make_base is annotated as returning A, but it actually returns an instance of B.
So it should dispatch to B.f, execute the passed lambda, and return the lambda result.
However, it looks like the program fails during typechecking before it can get as far as calling either A.f or B.f.
Result
$ codon run -release 04_factory_base_return_callable.codon
04_factory_base_return_callable.codon:15 (1-44): error: cannot typecheck 'print(make_base().f(lambda: False or True))'
04_factory_base_return_callable.codon:16 (1-45): error: cannot typecheck 'print(make_base().f(lambda: True and False))'Expected to print:
True
FalseSource: exaloop/codon