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 "Internal error ... local variable 'errstr' referenced before assignment during BoundFunction(...)" #5952

Merged
merged 2 commits into from
Jul 10, 2020
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
4 changes: 2 additions & 2 deletions numba/core/types/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,8 @@ def add_bt(error):
else:
bt = [""]
nd2indent = '\n{}'.format(2 * indent)
errstr += _termcolor.reset(nd2indent +
nd2indent.join(bt_as_lines))
errstr = _termcolor.reset(nd2indent +
nd2indent.join(_bt_as_lines(bt)))
return _termcolor.reset(errstr)
else:
add_bt = lambda X: ''
Expand Down
20 changes: 19 additions & 1 deletion numba/tests/test_errorhandling.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from numba.core.compiler_machinery import PassManager
from numba.core.types.functions import _err_reasons as error_reasons

from numba.tests.support import skip_parfors_unsupported
from numba.tests.support import (skip_parfors_unsupported, override_config,
SerialMixin)
import unittest

# used in TestMiscErrorHandling::test_handling_of_write_to_*_global
Expand Down Expand Up @@ -423,5 +424,22 @@ def foo():
self.assertIn("Type Restricted Function in function 'unknown'", excstr)


class TestDeveloperSpecificErrorMessages(SerialMixin, unittest.TestCase):

def test_bound_function_error_string(self):
# See PR #5952
def foo(x):
x.max(-1) # axis not supported

with override_config('DEVELOPER_MODE', 1):
with self.assertRaises(errors.TypingError) as raises:
njit("void(int64[:,:])")(foo)

excstr = str(raises.exception)
self.assertIn("AssertionError()", excstr)
self.assertIn("BoundFunction(array.max for array(int64, 2d, A))",
excstr)


if __name__ == '__main__':
unittest.main()