Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix fused function default argument coercion #5614

Merged
merged 1 commit into from Aug 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions Cython/Compiler/ExprNodes.py
Expand Up @@ -9718,6 +9718,8 @@ def analyse_default_args(self, env):
if not must_use_constants:
if arg.default.is_literal:
arg.default = DefaultLiteralArgNode(arg.pos, arg.default)
if arg.default.type:
arg.default = arg.default.coerce_to(arg.type, env)
else:
arg.is_dynamic = True
if arg.type.is_pyobject:
Expand Down
11 changes: 11 additions & 0 deletions tests/run/fused_def.pyx
Expand Up @@ -135,6 +135,17 @@ def opt_func(fused_t obj, cython.floating myf = 1.2, cython.integral myi = 7,
print cython.typeof(obj), cython.typeof(myf), cython.typeof(myi)
print obj, "%.2f" % myf, myi, "%.2f" % f, i

def non_fused_opt(fused_t obj, value=5):
"""
PyObject constants as parts of fused functions weren't being created correctly
which would lead this to crash
>>> non_fused_opt(0)
5
>>> non_fused_opt("str", 10)
10
"""
print value

def run_cyfunction_check():
"""
tp_base of the fused function was being set incorrectly meaning
Expand Down