prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN 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
  ```
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `numba/targets/optional.py`
  Content:
  ```
  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 FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
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"}], "after_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.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    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)\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)\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"}]}