Skip to content

Commit f503fc7

Browse files
committed
Fix a bug in class virtual method dispatch.
We don't produce LLVM arguments for 'Void' function arguments. Kind of an annoying feature of LLVM that its not allowed to pass 'void'. In any case, we have to be careful to filter these arguments out in all the right places.
1 parent 8837d5a commit f503fc7

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

typed_python/compiler/expression_conversion_context.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,9 @@ def finalize(self, expr, exceptionsTakeFrom=None):
773773

774774
def call_function_pointer(self, funcPtr, args, returnType):
775775
# force arguments to a type appropriate for argpassing
776-
native_args = [a.as_native_call_arg() for a in args if not a.expr_type.is_empty]
776+
args = [a for a in args if not a.expr_type.is_empty]
777+
778+
native_args = [a.as_native_call_arg() for a in args]
777779

778780
if returnType.is_pass_by_ref:
779781
nativeFunType = native_ast.Type.Function(

typed_python/compiler/tests/class_compilation_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,3 +3001,18 @@ def loopWithHasattr(c):
30013001
elapsedWithout = time.time() - t0
30023002

30033003
assert .6 < elapsedWithout / elapsedWith < 1.4
3004+
3005+
def test_virtual_dispatch_with_none(self):
3006+
class C(Class):
3007+
def f(self, x, y):
3008+
return (x, y, C)
3009+
3010+
class B(C):
3011+
def f(self, x, y):
3012+
return (x, y, B)
3013+
3014+
@Entrypoint
3015+
def callf(c: C):
3016+
return c.f(1, None)
3017+
3018+
callf(B())

0 commit comments

Comments
 (0)