From d1fd32364baaae9014d31b5757166e81395d2c4e Mon Sep 17 00:00:00 2001 From: Andrew Druk Date: Sat, 30 Jan 2021 22:10:32 +0200 Subject: [PATCH] Dev: fix swift compiler warnings in generated code --- .../com/readdle/codegen/SwiftFuncDescriptor.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java b/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java index 57836aa..1bbe2ed 100644 --- a/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java +++ b/compiler/src/main/java/com/readdle/codegen/SwiftFuncDescriptor.java @@ -113,7 +113,21 @@ public void generateCode(SwiftWriter swiftWriter, String javaFullName, String sw swiftWriter.emitStatement(String.format("let %s: %s%s", param.name, param.swiftType.swiftType, param.isOptional ? "?" : "")); } - boolean shouldCatchPreamble = params.size() > 0 || !isStatic; + + boolean shouldCatchPreamble = false; + if (isStatic) { + for (SwiftParamDescriptor param : params) { + // primitive types constructors not throw + if (param.isOptional || !param.isPrimitive()) { + shouldCatchPreamble = true; + break; + } + } + } + else { + shouldCatchPreamble = true; + } + if (shouldCatchPreamble) { swiftWriter.emitStatement("do {"); }