prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  Lowering error when removing element from the middle of linked list
  Hi
  
  I am having a hard time trying to figure out an error when I reassign "element_0.next = element_1.next" of a linked list. I posted my error at stackoverflow: https://stackoverflow.com/questions/47232035/numba-lowering-error-when-reassigning-next-link-of-a-linked-list-element
  
  I am creating this issue to make it closer to you.
  
  I have visited most of your examples and documentation pages, no ideas whatsoever.
  
  What am I missing?
  
  I am using numba **0.35.0** (from Anaconda, python 3.6.2).
  
  Thanks
  
  </issue>
  <code>
  [start of numba/targets/optional.py]
  1 from __future__ import print_function, absolute_import, division
  2 
  3 from numba import types, cgutils
  4 
  5 from .imputils import (lower_cast, lower_builtin, lower_getattr_generic,
  6                        impl_ret_untracked)
  7 
  8 
  9 def always_return_true_impl(context, builder, sig, args):
  10     return cgutils.true_bit
  11 
  12 
  13 def always_return_false_impl(context, builder, sig, args):
  14     return cgutils.false_bit
  15 
  16 
  17 def optional_is_none(context, builder, sig, args):
  18     """
  19     Check if an Optional value is invalid
  20     """
  21     [lty, rty] = sig.args
  22     [lval, rval] = args
  23 
  24     # Make sure None is on the right
  25     if lty == types.none:
  26         lty, rty = rty, lty
  27         lval, rval = rval, lval
  28 
  29     opt_type = lty
  30     opt_val = lval
  31 
  32     opt = context.make_helper(builder, opt_type, opt_val)
  33     res = builder.not_(cgutils.as_bool_bit(builder, opt.valid))
  34     return impl_ret_untracked(context, builder, sig.return_type, res)
  35 
  36 
  37 # None is/not None
  38 lower_builtin('is', types.none, types.none)(always_return_true_impl)
  39 
  40 # Optional is None
  41 lower_builtin('is', types.Optional, types.none)(optional_is_none)
  42 lower_builtin('is', types.none, types.Optional)(optional_is_none)
  43 
  44 
  45 @lower_getattr_generic(types.Optional)
  46 def optional_getattr(context, builder, typ, value, attr):
  47     """
  48     Optional.__getattr__ => redirect to the wrapped type.
  49     """
  50     inner_type = typ.type
  51     val = context.cast(builder, value, typ, inner_type)
  52     imp = context.get_getattr(inner_type, attr)
  53     return imp(context, builder, inner_type, val, attr)
  54 
  55 
  56 @lower_cast(types.Optional, types.Optional)
  57 def optional_to_optional(context, builder, fromty, toty, val):
  58     """
  59     The handling of optional->optional cast must be special cased for
  60     correct propagation of None value.  Given type T and U. casting of
  61     T? to U? (? denotes optional) should always succeed.   If the from-value
  62     is None, the None value the casted value (U?) should be None; otherwise,
  63     the from-value is casted to U. This is different from casting T? to U,
  64     which requires the from-value must not be None.
  65     """
  66     optval = context.make_helper(builder, fromty, value=val)
  67     validbit = cgutils.as_bool_bit(builder, optval.valid)
  68     # Create uninitialized optional value
  69     outoptval = context.make_helper(builder, toty)
  70 
  71     with builder.if_else(validbit) as (is_valid, is_not_valid):
  72         with is_valid:
  73             # Cast internal value
  74             outoptval.valid = cgutils.true_bit
  75             outoptval.data = context.cast(builder, optval.data,
  76                                           fromty.type, toty.type)
  77 
  78         with is_not_valid:
  79             # Store None to result
  80             outoptval.valid = cgutils.false_bit
  81             outoptval.data = cgutils.get_null_value(
  82                 outoptval.data.type)
  83 
  84     return outoptval._getvalue()
  85 
  86 
  87 @lower_cast(types.Any, types.Optional)
  88 def any_to_optional(context, builder, fromty, toty, val):
  89     if fromty == types.none:
  90         return context.make_optional_none(builder, toty.type)
  91     else:
  92         val = context.cast(builder, val, fromty, toty.type)
  93         return context.make_optional_value(builder, toty.type, val)
  94 
  95 
  96 @lower_cast(types.Optional, types.Any)
  97 @lower_cast(types.Optional, types.Boolean)
  98 def optional_to_any(context, builder, fromty, toty, val):
  99     optval = context.make_helper(builder, fromty, value=val)
  100     validbit = cgutils.as_bool_bit(builder, optval.valid)
  101     with builder.if_then(builder.not_(validbit), likely=False):
  102         msg = "expected %s, got None" % (fromty.type,)
  103         context.call_conv.return_user_exc(builder, TypeError, (msg,))
  104 
  105     return context.cast(builder, optval.data, fromty.type, toty)
  106
  [end of numba/targets/optional.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/numba/targets/optional.py b/numba/targets/optional.py
  --- a/numba/targets/optional.py
  +++ b/numba/targets/optional.py
  @@ -1,9 +1,9 @@
   from __future__ import print_function, absolute_import, division
   
  -from numba import types, cgutils
  +from numba import types, cgutils, typing
   
   from .imputils import (lower_cast, lower_builtin, lower_getattr_generic,
  -                       impl_ret_untracked)
  +                       impl_ret_untracked, lower_setattr_generic)
   
   
   def always_return_true_impl(context, builder, sig, args):
  @@ -53,6 +53,21 @@
       return imp(context, builder, inner_type, val, attr)
   
   
  +@lower_setattr_generic(types.Optional)
  +def optional_setattr(context, builder, sig, args, attr):
  +    """
  +    Optional.__setattr__ => redirect to the wrapped type.
  +    """
  +    basety, valty = sig.args
  +    target, val = args
  +    target_type = basety.type
  +    target = context.cast(builder, target, basety, target_type)
  +
  +    newsig = typing.signature(sig.return_type, target_type, valty)
  +    imp = context.get_setattr(attr, newsig)
  +    return imp(builder, (target, val))
  +
  +
   @lower_cast(types.Optional, types.Optional)
   def optional_to_optional(context, builder, fromty, toty, val):
       """
  
verification_info: {"golden_diff": "diff --git a/numba/targets/optional.py b/numba/targets/optional.py\n--- a/numba/targets/optional.py\n+++ b/numba/targets/optional.py\n@@ -1,9 +1,9 @@\n from __future__ import print_function, absolute_import, division\n \n-from numba import types, cgutils\n+from numba import types, cgutils, typing\n \n from .imputils import (lower_cast, lower_builtin, lower_getattr_generic,\n-                       impl_ret_untracked)\n+                       impl_ret_untracked, lower_setattr_generic)\n \n \n def always_return_true_impl(context, builder, sig, args):\n@@ -53,6 +53,21 @@\n     return imp(context, builder, inner_type, val, attr)\n \n \n+@lower_setattr_generic(types.Optional)\n+def optional_setattr(context, builder, sig, args, attr):\n+    \"\"\"\n+    Optional.__setattr__ => redirect to the wrapped type.\n+    \"\"\"\n+    basety, valty = sig.args\n+    target, val = args\n+    target_type = basety.type\n+    target = context.cast(builder, target, basety, target_type)\n+\n+    newsig = typing.signature(sig.return_type, target_type, valty)\n+    imp = context.get_setattr(attr, newsig)\n+    return imp(builder, (target, val))\n+\n+\n @lower_cast(types.Optional, types.Optional)\n def optional_to_optional(context, builder, fromty, toty, val):\n     \"\"\"\n", "issue": "Lowering error when removing element from the middle of linked list\nHi\r\n\r\nI am having a hard time trying to figure out an error when I reassign \"element_0.next = element_1.next\" of a linked list. I posted my error at stackoverflow: https://stackoverflow.com/questions/47232035/numba-lowering-error-when-reassigning-next-link-of-a-linked-list-element\r\n\r\nI am creating this issue to make it closer to you.\r\n\r\nI have visited most of your examples and documentation pages, no ideas whatsoever.\r\n\r\nWhat am I missing?\r\n\r\nI am using numba **0.35.0** (from Anaconda, python 3.6.2).\r\n\r\nThanks\n", "before_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom numba import types, cgutils\n\nfrom .imputils import (lower_cast, lower_builtin, lower_getattr_generic,\n                       impl_ret_untracked)\n\n\ndef always_return_true_impl(context, builder, sig, args):\n    return cgutils.true_bit\n\n\ndef always_return_false_impl(context, builder, sig, args):\n    return cgutils.false_bit\n\n\ndef optional_is_none(context, builder, sig, args):\n    \"\"\"\n    Check if an Optional value is invalid\n    \"\"\"\n    [lty, rty] = sig.args\n    [lval, rval] = args\n\n    # Make sure None is on the right\n    if lty == types.none:\n        lty, rty = rty, lty\n        lval, rval = rval, lval\n\n    opt_type = lty\n    opt_val = lval\n\n    opt = context.make_helper(builder, opt_type, opt_val)\n    res = builder.not_(cgutils.as_bool_bit(builder, opt.valid))\n    return impl_ret_untracked(context, builder, sig.return_type, res)\n\n\n# None is/not None\nlower_builtin('is', types.none, types.none)(always_return_true_impl)\n\n# Optional is None\nlower_builtin('is', types.Optional, types.none)(optional_is_none)\nlower_builtin('is', types.none, types.Optional)(optional_is_none)\n\n\n@lower_getattr_generic(types.Optional)\ndef optional_getattr(context, builder, typ, value, attr):\n    \"\"\"\n    Optional.__getattr__ => redirect to the wrapped type.\n    \"\"\"\n    inner_type = typ.type\n    val = context.cast(builder, value, typ, inner_type)\n    imp = context.get_getattr(inner_type, attr)\n    return imp(context, builder, inner_type, val, attr)\n\n\n@lower_cast(types.Optional, types.Optional)\ndef optional_to_optional(context, builder, fromty, toty, val):\n    \"\"\"\n    The handling of optional->optional cast must be special cased for\n    correct propagation of None value.  Given type T and U. casting of\n    T? to U? (? denotes optional) should always succeed.   If the from-value\n    is None, the None value the casted value (U?) should be None; otherwise,\n    the from-value is casted to U. This is different from casting T? to U,\n    which requires the from-value must not be None.\n    \"\"\"\n    optval = context.make_helper(builder, fromty, value=val)\n    validbit = cgutils.as_bool_bit(builder, optval.valid)\n    # Create uninitialized optional value\n    outoptval = context.make_helper(builder, toty)\n\n    with builder.if_else(validbit) as (is_valid, is_not_valid):\n        with is_valid:\n            # Cast internal value\n            outoptval.valid = cgutils.true_bit\n            outoptval.data = context.cast(builder, optval.data,\n                                          fromty.type, toty.type)\n\n        with is_not_valid:\n            # Store None to result\n            outoptval.valid = cgutils.false_bit\n            outoptval.data = cgutils.get_null_value(\n                outoptval.data.type)\n\n    return outoptval._getvalue()\n\n\n@lower_cast(types.Any, types.Optional)\ndef any_to_optional(context, builder, fromty, toty, val):\n    if fromty == types.none:\n        return context.make_optional_none(builder, toty.type)\n    else:\n        val = context.cast(builder, val, fromty, toty.type)\n        return context.make_optional_value(builder, toty.type, val)\n\n\n@lower_cast(types.Optional, types.Any)\n@lower_cast(types.Optional, types.Boolean)\ndef optional_to_any(context, builder, fromty, toty, val):\n    optval = context.make_helper(builder, fromty, value=val)\n    validbit = cgutils.as_bool_bit(builder, optval.valid)\n    with builder.if_then(builder.not_(validbit), likely=False):\n        msg = \"expected %s, got None\" % (fromty.type,)\n        context.call_conv.return_user_exc(builder, TypeError, (msg,))\n\n    return context.cast(builder, optval.data, fromty.type, toty)\n", "path": "numba/targets/optional.py"}]}