aboutsummaryrefslogtreecommitdiff
path: root/tools/lxdrgen-swift.awk
diff options
context:
space:
mode:
authorPřemysl Eric Janouch <p@janouch.name>2023-07-06 06:38:25 +0200
committerPřemysl Eric Janouch <p@janouch.name>2023-07-06 06:54:23 +0200
commitbe9a3e693e019ab4797ea093bedde3ca39398e6e (patch)
tree86f93a5271d936cbecab25e7f031216663902bb9 /tools/lxdrgen-swift.awk
parent53197b51e5edbb1b195070523dbfd8d9ba05d847 (diff)
downloadliberty-be9a3e693e019ab4797ea093bedde3ca39398e6e.tar.gz
liberty-be9a3e693e019ab4797ea093bedde3ca39398e6e.tar.xz
liberty-be9a3e693e019ab4797ea093bedde3ca39398e6e.zip
lxdrgen-swift: fix warnings with exhaustive unions
Diffstat (limited to 'tools/lxdrgen-swift.awk')
-rw-r--r--tools/lxdrgen-swift.awk12
1 files changed, 6 insertions, 6 deletions
diff --git a/tools/lxdrgen-swift.awk b/tools/lxdrgen-swift.awk
index 28554c9..33b1f73 100644
--- a/tools/lxdrgen-swift.awk
+++ b/tools/lxdrgen-swift.awk
@@ -246,7 +246,7 @@ function codegen_union_struct(name, casename, cg, scg, swifttype) {
delete scg[i]
}
-function codegen_union(name, cg, swifttype, init) {
+function codegen_union(name, cg, exhaustive, swifttype, init) {
# Classes don't have automatic member-wise initializers,
# thus using structs and protocols.
swifttype = PrefixCamel name
@@ -255,6 +255,10 @@ function codegen_union(name, cg, swifttype, init) {
print "\tvar " cg["tagname"] ": " CodegenSwiftType[cg["tagtype"]] " { get }"
print "}"
+ if (!exhaustive)
+ append(cg, "cases", "\tdefault:\n" \
+ "\t\tthrow RelayReader.ReadError.unexpectedValue\n")
+
init = decapitalize(swifttype)
print ""
print "public func " init \
@@ -262,11 +266,7 @@ function codegen_union(name, cg, swifttype, init) {
print "\tlet " cg["tagname"] ": " CodegenSwiftType[cg["tagtype"]] \
" = try from.read()"
print "\tswitch " cg["tagname"] " {"
- # TODO: Only generate the default if there are remaining values,
- # so that swiftc doesn't produce warnings.
- print cg["cases"] "\tdefault:"
- print "\t\tthrow RelayReader.ReadError.unexpectedValue"
- print"\t}"
+ print cg["cases"] "\t}"
print "}"
CodegenSwiftType[name] = swifttype