From be9a3e693e019ab4797ea093bedde3ca39398e6e Mon Sep 17 00:00:00 2001 From: Přemysl Eric Janouch Date: Thu, 6 Jul 2023 06:38:25 +0200 Subject: lxdrgen-swift: fix warnings with exhaustive unions --- tools/lxdrgen-swift.awk | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'tools/lxdrgen-swift.awk') 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 -- cgit v1.2.3-54-g00ecf