Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unreachable code warnings when all reconnectable swift routes have compat wrappers #347

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions stone/backends/swift_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,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
Loading