Repository: numba/numba

Issue:
list of list (nested build_list) fails on master
<!--

Thanks for opening an issue! To help the Numba team handle your information
efficiently, please first ensure that there is no other issue present that
already describes the issue you have
(search at https://github.com/numba/numba/issues?&q=is%3Aissue).

-->

## Reporting a bug

<!--

Before submitting a bug report please ensure that you can check off these boxes:

-->

- [x] I have tried using the latest ~released~ master version of Numba (most recent is
 visible in the change log (https://github.com/numba/numba/blob/master/CHANGE_LOG).
- [x] I have included below a minimal working reproducer (if you are unsure how
 to write one see http://matthewrocklin.com/blog/work/2018/02/28/minimal-bug-reports).

<!--

Please include details of the bug here, including, if applicable, what you
expected to happen!

-->
Seems related to the new list initial value feature. @stuartarchibald ?

```python
In [7]: numba.__version__
Out[7]: '0.51.0dev0+497.g4aceb2727'

In [8]: numba.njit(lambda: [[1, 2, 3, 4, 5], [1, 2, 3, 4, 6]])()
---------------------------------------------------------------------------
TypingError                               Traceback (most recent call last)
<ipython-input-8-7fdc3277fbc9> in <module>
----> 1 numba.njit(lambda: [[1, 2, 3, 4, 5], [1, 2, 3, 4, 6]])()

~/dev/numba/numba/core/dispatcher.py in _compile_for_args(self, *args, **kws)
    413                 e.patch_message(msg)
    414
--> 415             error_rewrite(e, 'typing')
    416         except errors.UnsupportedError as e:
    417             # Something unsupported is present in the user code, add help info

~/dev/numba/numba/core/dispatcher.py in error_rewrite(e, issue_type)
    356                 raise e
    357             else:
--> 358                 reraise(type(e), e, None)
    359
    360         argtypes = []

~/dev/numba/numba/core/utils.py in reraise(tp, value, tb)
     78         value = tp()
     79     if value.__traceback__ is not tb:
---> 80         raise value.with_traceback(tb)
     81     raise value
     82

TypingError: Failed in nopython mode pipeline (step: nopython frontend)
Internal error at <numba.core.typeinfer.BuildListConstraint object at 0x7fd342d54f70>.
'list' object has no attribute 'initial_value'
During: typing of <class 'numba.core.types.containers.List'> at <ipython-input-8-7fdc3277fbc9> (1)
Enable logging at debug level for details.

File "<ipython-input-8-7fdc3277fbc9>", line 1:
numba.njit(lambda: [[1, 2, 3, 4, 5], [1, 2, 3, 4, 6]])()
^
```


Discussion:

Resolving patch:
diff --git a/numba/core/types/containers.py b/numba/core/types/containers.py
--- a/numba/core/types/containers.py
+++ b/numba/core/types/containers.py
@@ -442,7 +442,7 @@ def unify(self, typingctx, other):
                     use = siv
                     if siv is None:
                         use = oiv
-                    return List(dtype, reflected, use.initial_value)
+                    return List(dtype, reflected, use)
                 else:
                     return List(dtype, reflected)
 


Test patch:
diff --git a/numba/tests/test_lists.py b/numba/tests/test_lists.py
--- a/numba/tests/test_lists.py
+++ b/numba/tests/test_lists.py
@@ -1516,6 +1516,22 @@ def foo():
             larg = baz.signatures[0][0]
             self.assertEqual(larg.initial_value, iv)
 
+    def test_list_of_list_ctor(self):
+        # see issue 6082
+        @njit
+        def bar(x):
+            pass
+
+        @njit
+        def foo():
+            x = [[1, 2, 3, 4, 5], [1, 2, 3, 4, 6]]
+            bar(x)
+
+        foo()
+        larg = bar.signatures[0][0]
+        self.assertEqual(larg.initial_value, None)
+        self.assertEqual(larg.dtype.initial_value, None)
+
 
 class TestLiteralLists(MemoryLeakMixin, TestCase):