Repository: numba/numba

Issue:
generator error if bool yielded
version 0.32
```
import numba as nb

@nb.jit(nopython=True)
def gf():
    yield 0, True

print(list(gf()))
```
will result in error:

> Traceback (most recent call last):
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/errors.py", line 243, in new_error_context
>     yield
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 210, in lower_block
>     self.lower_inst(inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 256, in lower_inst
>     val = self.lower_assign(ty, inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 426, in lower_assign
>     res = self.lower_yield(ty, value)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 441, in lower_yield
>     self.call_conv.return_value(self.builder, val)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/targets/callconv.py", line 329, in return_value
>     (str(retval.type), str(retptr.type.pointee))
> AssertionError: ('{i64, i1}', '{i64, i8}')
> 

generator error if bool yielded
version 0.32
```
import numba as nb

@nb.jit(nopython=True)
def gf():
    yield 0, True

print(list(gf()))
```
will result in error:

> Traceback (most recent call last):
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/errors.py", line 243, in new_error_context
>     yield
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 210, in lower_block
>     self.lower_inst(inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 256, in lower_inst
>     val = self.lower_assign(ty, inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 426, in lower_assign
>     res = self.lower_yield(ty, value)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 441, in lower_yield
>     self.call_conv.return_value(self.builder, val)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/targets/callconv.py", line 329, in return_value
>     (str(retval.type), str(retptr.type.pointee))
> AssertionError: ('{i64, i1}', '{i64, i8}')
> 

generator error if bool yielded
version 0.32
```
import numba as nb

@nb.jit(nopython=True)
def gf():
    yield 0, True

print(list(gf()))
```
will result in error:

> Traceback (most recent call last):
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/errors.py", line 243, in new_error_context
>     yield
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 210, in lower_block
>     self.lower_inst(inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 256, in lower_inst
>     val = self.lower_assign(ty, inst)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 426, in lower_assign
>     res = self.lower_yield(ty, value)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/lowering.py", line 441, in lower_yield
>     self.call_conv.return_value(self.builder, val)
>   File "/fw/Anaconda/anaconda/lib/python3.5/site-packages/numba/targets/callconv.py", line 329, in return_value
>     (str(retval.type), str(retptr.type.pointee))
> AssertionError: ('{i64, i1}', '{i64, i8}')
> 



Discussion:
Thanks for the report. I can replicate. It also fails for:

```python
def gen():
    yield True
```
and indeed seemingly anything yielding bools.

It seems to be that the `i1` isn't being handled correctly in the generator lowering.

Thanks for the report. I can replicate. It also fails for:

```python
def gen():
    yield True
```
and indeed seemingly anything yielding bools.

It seems to be that the `i1` isn't being handled correctly in the generator lowering.

Thanks for the report. I can replicate. It also fails for:

```python
def gen():
    yield True
```
and indeed seemingly anything yielding bools.

It seems to be that the `i1` isn't being handled correctly in the generator lowering.


Resolving patch:
diff --git a/numba/lowering.py b/numba/lowering.py
--- a/numba/lowering.py
+++ b/numba/lowering.py
@@ -450,8 +450,16 @@ def lower_yield(self, retty, inst):
         # Yield to caller
         val = self.loadvar(inst.value.name)
         typ = self.typeof(inst.value.name)
-        val = self.context.cast(self.builder, val, typ, self.gentype.yield_type)
-        self.call_conv.return_value(self.builder, val)
+
+        # cast the local val to the type yielded
+        yret = self.context.cast(self.builder, val, typ,
+                                    self.gentype.yield_type)
+
+        # get the return repr of yielded value
+        retval = self.context.get_return_value(self.builder, typ, yret)
+        
+        # return
+        self.call_conv.return_value(self.builder, retval)
 
         # Resumption point
         y.lower_yield_resume()


Test patch:
diff --git a/numba/tests/test_generators.py b/numba/tests/test_generators.py
--- a/numba/tests/test_generators.py
+++ b/numba/tests/test_generators.py
@@ -113,6 +113,9 @@ def gen_ndenumerate(arr):
         yield tup
 
 
+def gen_bool():
+    yield True
+
 class TestGenerators(MemoryLeakMixin, TestCase):
     def check_generator(self, pygen, cgen):
         self.assertEqual(next(cgen), next(pygen))
@@ -245,6 +248,20 @@ def test_gen8(self):
     def test_gen8_objmode(self):
         self.check_gen8(forceobj=True)
 
+    def check_gen9(self, flags=no_pyobj_flags):
+        pyfunc = gen_bool
+        cr = compile_isolated(pyfunc, (), flags=flags)
+        pygen = pyfunc()
+        cgen = cr.entry_point()
+        self.check_generator(pygen, cgen)
+
+    @tag('important')
+    def test_gen9(self):
+        self.check_gen9(flags=no_pyobj_flags)
+
+    def test_gen9_objmode(self):
+        self.check_gen9(flags=forceobj_flags)
+
     def check_consume_generator(self, gen_func):
         cgen = jit(nopython=True)(gen_func)
         cfunc = jit(nopython=True)(make_consumer(cgen))