From 83877c71f9c28acf9921518a8187a7bbec52f74e Mon Sep 17 00:00:00 2001 From: Julian Locke Date: Tue, 27 Aug 2024 13:36:52 -0400 Subject: [PATCH] Fix unreachable code warnings when all reconnectable swift routes have compatibiltiy wrappers (#347) --- stone/backends/swift_client.py | 7 +----- .../backends/swift_rsrc/ObjCRequestBox.jinja | 22 +++++++++---------- 2 files changed, 11 insertions(+), 18 deletions(-) diff --git a/stone/backends/swift_client.py b/stone/backends/swift_client.py index 14144123..2a47dac7 100644 --- a/stone/backends/swift_client.py +++ b/stone/backends/swift_client.py @@ -254,15 +254,10 @@ def _generate_request_boxes(self, api): template = self._jinja_template("ObjCRequestBox.jinja") template.globals = template_globals - # don't include the default case in the generated switch statement if it's unreachable - include_default_in_switch = True - # TODO(jlocke): implement this to eliminate the unreachable code warning - output = template.render( background_compatible_routes=background_compatible_routes, background_objc_routes=background_objc_routes, - class_name=swift_class_name, - include_default_in_switch=include_default_in_switch + class_name=swift_class_name ) file_name = 'DBX{}RequestBox.swift'.format(self.args.class_name) diff --git a/stone/backends/swift_rsrc/ObjCRequestBox.jinja b/stone/backends/swift_rsrc/ObjCRequestBox.jinja index 4ca3cb32..735adae1 100644 --- a/stone/backends/swift_rsrc/ObjCRequestBox.jinja +++ b/stone/backends/swift_rsrc/ObjCRequestBox.jinja @@ -9,18 +9,16 @@ import SwiftyDropbox extension {{ class_name }} { var objc: DBXRequest { - switch self { - {% for route_args_data in background_objc_routes %} - {% set namespace = route_args_data[0] %} - {% set route = route_args_data[1] %} - {% set args_data = route_args_data[2] %} - case .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}(let swift): - return {{ fmt_route_objc_class(namespace, route, args_data) }}(swift: swift) - {% endfor %} - {% if include_default_in_switch %} - default: - fatalError("For Obj-C compatibility, add this route to the Objective-C compatibility module allow-list") - {% endif %} + {% for route_args_data in background_objc_routes %} + {% set namespace = route_args_data[0] %} + {% set route = route_args_data[1] %} + {% set args_data = route_args_data[2] %} + if case .{{ fmt_func_namespace(route.name, route.version, namespace.name) }}(let swift) = self { + return {{ fmt_route_objc_class(namespace, route, args_data) }}(swift: swift) + } + {% endfor %} + else { + fatalError("For Obj-C compatibility, add this route to the Objective-C compatibility module allow-list") } } }