prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  LinkedList jitclass example is broken
  ```
  Internal error:
  TypeError: Invalid store of %"deferred.4329823704.value" to {i8*, {i32, {%"deferred.4329823704.data", i8}}*} in <numba.datamodel.models.OptionalModel object at 0x106713278>
  File "linkedlist.py", line 53
  ```
  
  
  </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
  6 
  7 
  8 def make_optional(valtype):
  9     """
  10     Return the Structure representation of a optional value
  11     """
  12     return cgutils.create_struct_proxy(types.Optional(valtype))
  13 
  14 
  15 def always_return_true_impl(context, builder, sig, args):
  16     return cgutils.true_bit
  17 
  18 
  19 def always_return_false_impl(context, builder, sig, args):
  20     return cgutils.false_bit
  21 
  22 
  23 @lower_cast(types.Any, types.Optional)
  24 def any_to_optional(context, builder, fromty, toty, val):
  25     if fromty == types.none:
  26         return context.make_optional_none(builder, toty.type)
  27     else:
  28         val = context.cast(builder, val, fromty, toty.type)
  29         return context.make_optional_value(builder, toty.type, val)
  30 
  31 @lower_cast(types.Optional, types.Any)
  32 def optional_to_any(context, builder, fromty, toty, val):
  33     optty = context.make_optional(fromty)
  34     optval = optty(context, builder, value=val)
  35     validbit = cgutils.as_bool_bit(builder, optval.valid)
  36     with builder.if_then(builder.not_(validbit), likely=False):
  37         msg = "expected %s, got None" % (fromty.type,)
  38         context.call_conv.return_user_exc(builder, TypeError, (msg,))
  39 
  40     return optval.data
  41
  [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
  @@ -20,6 +20,39 @@
       return cgutils.false_bit
   
   
  +@lower_cast(types.Optional, types.Optional)
  +def optional_to_optional(context, builder, fromty, toty, val):
  +    """
  +    The handling of optional->optional cast must be special cased for
  +    correct propagation of None value.  Given type T and U. casting of
  +    T? to U? (? denotes optional) should always succeed.   If the from-value
  +    is None, the None value the casted value (U?) should be None; otherwise,
  +    the from-value is casted to U. This is different from casting T? to U,
  +    which requires the from-value must not be None.
  +    """
  +    optty = context.make_optional(fromty)
  +    optval = optty(context, builder, value=val)
  +    validbit = cgutils.as_bool_bit(builder, optval.valid)
  +    # Create uninitialized optional value
  +    outoptty = context.make_optional(toty)
  +    outoptval = outoptty(context, builder)
  +
  +    with builder.if_else(validbit) as (is_valid, is_not_valid):
  +        with is_valid:
  +            # Cast internal value
  +            outoptval.valid = cgutils.true_bit
  +            outoptval.data = context.cast(builder, optval.data,
  +                                          fromty.type, toty.type)
  +
  +        with is_not_valid:
  +            # Store None to result
  +            outoptval.valid = cgutils.false_bit
  +            outoptval.data = cgutils.get_null_value(
  +                outoptval.data.type)
  +
  +    return outoptval._getvalue()
  +
  +
   @lower_cast(types.Any, types.Optional)
   def any_to_optional(context, builder, fromty, toty, val):
       if fromty == types.none:
  @@ -28,6 +61,7 @@
           val = context.cast(builder, val, fromty, toty.type)
           return context.make_optional_value(builder, toty.type, val)
   
  +
   @lower_cast(types.Optional, types.Any)
   def optional_to_any(context, builder, fromty, toty, val):
       optty = context.make_optional(fromty)
  
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@@ -20,6 +20,39 @@\n     return cgutils.false_bit\n \n \n+@lower_cast(types.Optional, types.Optional)\n+def 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+    optty = context.make_optional(fromty)\n+    optval = optty(context, builder, value=val)\n+    validbit = cgutils.as_bool_bit(builder, optval.valid)\n+    # Create uninitialized optional value\n+    outoptty = context.make_optional(toty)\n+    outoptval = outoptty(context, builder)\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)\n def any_to_optional(context, builder, fromty, toty, val):\n     if fromty == types.none:\n@@ -28,6 +61,7 @@\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 def optional_to_any(context, builder, fromty, toty, val):\n     optty = context.make_optional(fromty)\n", "issue": "LinkedList jitclass example is broken\n```\nInternal error:\nTypeError: Invalid store of %\"deferred.4329823704.value\" to {i8*, {i32, {%\"deferred.4329823704.data\", i8}}*} in <numba.datamodel.models.OptionalModel object at 0x106713278>\nFile \"linkedlist.py\", line 53\n```\n\n", "before_files": [{"content": "from __future__ import print_function, absolute_import, division\n\nfrom numba import types, cgutils\n\nfrom .imputils import lower_cast\n\n\ndef make_optional(valtype):\n    \"\"\"\n    Return the Structure representation of a optional value\n    \"\"\"\n    return cgutils.create_struct_proxy(types.Optional(valtype))\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\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@lower_cast(types.Optional, types.Any)\ndef optional_to_any(context, builder, fromty, toty, val):\n    optty = context.make_optional(fromty)\n    optval = optty(context, builder, 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 optval.data\n", "path": "numba/targets/optional.py"}]}