diff options
author | Robert Bradshaw <robertwb@gmail.com> | 2016-03-04 12:03:22 -0800 |
---|---|---|
committer | Robert Bradshaw <robertwb@gmail.com> | 2016-03-04 12:03:22 -0800 |
commit | b5955fdf1024f268b0f52405274d90721000abde (patch) | |
tree | 85f982b2917c7e05932aaa114249c738eb6b8bd5 | |
parent | d59968c05c1bc4617b38427376053d13bec209e5 (diff) | |
parent | e1fd79496c70db74a902120d2ec94a2cda955c83 (diff) | |
download | cython-b5955fdf1024f268b0f52405274d90721000abde.tar.gz |
Merge pull request #495 from insertinterestingnamehere/const_args
Don't error out when non-const value is passed as const function parameter
-rw-r--r-- | Cython/Compiler/ExprNodes.py | 2 | ||||
-rw-r--r-- | tests/errors/cpp_no_auto_conversion.pyx | 2 | ||||
-rw-r--r-- | tests/run/non_const_as_const_arg.pyx | 10 |
3 files changed, 13 insertions, 1 deletions
diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index 5b39da436..0a47dca3b 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -5052,6 +5052,8 @@ class SimpleCallNode(CallNode): for i in range(min(max_nargs, actual_nargs)): formal_arg = func_type.args[i] formal_type = formal_arg.type + if formal_type.is_const: + formal_type = formal_type.const_base_type arg = args[i].coerce_to(formal_type, env) if formal_arg.not_none: # C methods must do the None checks at *call* time diff --git a/tests/errors/cpp_no_auto_conversion.pyx b/tests/errors/cpp_no_auto_conversion.pyx index eb7889ba5..1312c3e17 100644 --- a/tests/errors/cpp_no_auto_conversion.pyx +++ b/tests/errors/cpp_no_auto_conversion.pyx @@ -19,5 +19,5 @@ cdef long long e = constructor_overload(17) _ERRORS = u""" -18:40: Cannot assign type 'long' to 'const wrapped_int' +18:40: Cannot assign type 'long' to 'wrapped_int' """ diff --git a/tests/run/non_const_as_const_arg.pyx b/tests/run/non_const_as_const_arg.pyx new file mode 100644 index 000000000..eca3d84ca --- /dev/null +++ b/tests/run/non_const_as_const_arg.pyx @@ -0,0 +1,10 @@ +cdef double f(const double a, const double b, const double c): + return a + b - c + +def test_non_const_as_const_arg(): + """ + >>> test_non_const_as_const_arg() + 1.0 + """ + cdef double a = 1., b = 1., c = 1. + return f(a, b, c) |