Skip to content

Commit

Permalink
Fix unreachable code warnings when all reconnectable swift routes hav…
Browse files Browse the repository at this point in the history
…e compatibiltiy wrappers (#347)
  • Loading branch information
julianlocke committed Aug 27, 2024
1 parent 8f51a4b commit 83877c7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
7 changes: 1 addition & 6 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 10 additions & 12 deletions stone/backends/swift_rsrc/ObjCRequestBox.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}
}
Expand Down

0 comments on commit 83877c7

Please sign in to comment.