Skip to content

Commit

Permalink
Merge pull request #2938 from square/edge_case_defaulted_value
Browse files Browse the repository at this point in the history
[swift] handle edge for defaulted value when it collides a sub-type name
  • Loading branch information
dnkoutso authored May 13, 2024
2 parents da663ee + cc3149d commit f7a44ab
Show file tree
Hide file tree
Showing 37 changed files with 243 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extension OneofOptions : Sendable {

extension OneofOptions : ProtoDefaultedValue {

public static var defaultedValue: OneofOptions {
OneofOptions()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
4 changes: 2 additions & 2 deletions wire-runtime-swift/src/test/swift/sample/Dinosaur.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ extension Dinosaur : Sendable {

extension Dinosaur : ProtoDefaultedValue {

public static var defaultedValue: Dinosaur {
Dinosaur()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ import io.outfoxx.swiftpoet.ParameterSpec
import io.outfoxx.swiftpoet.ParameterizedTypeName
import io.outfoxx.swiftpoet.PropertySpec
import io.outfoxx.swiftpoet.STRING
import io.outfoxx.swiftpoet.SelfTypeName
import io.outfoxx.swiftpoet.TypeAliasSpec
import io.outfoxx.swiftpoet.TypeName
import io.outfoxx.swiftpoet.TypeSpec
Expand Down Expand Up @@ -394,10 +395,8 @@ class SwiftGenerator private constructor(
val defaultedValueExtension = ExtensionSpec.builder(structType)
.addSuperType(protoDefaultedValue)
.addProperty(
PropertySpec.varBuilder("defaultedValue", structType, PUBLIC, STATIC).getter(
FunctionSpec.getterBuilder().addCode(
CodeBlock.of("%T()\n", structType),
).build(),
PropertySpec.varBuilder("defaultedValue", SelfTypeName.INSTANCE.makeNonOptional(), PUBLIC, STATIC).getter(
FunctionSpec.getterBuilder().addCode(".init()\n").build(),
).build(),
).build()

Expand Down
4 changes: 2 additions & 2 deletions wire-tests-proto3-swift/src/main/swift/ContainsDuration.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extension ContainsDuration : Sendable {

extension ContainsDuration : ProtoDefaultedValue {

public static var defaultedValue: ContainsDuration {
ContainsDuration()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extension ContainsTimestamp : Sendable {

extension ContainsTimestamp : ProtoDefaultedValue {

public static var defaultedValue: ContainsTimestamp {
ContainsTimestamp()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
4 changes: 2 additions & 2 deletions wire-tests-swift/manifest/module_one/ExtensionMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extension ExtensionMessage : Sendable {

extension ExtensionMessage : ProtoDefaultedValue {

public static var defaultedValue: ExtensionMessage {
ExtensionMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ extension SwiftModuleTwoMessage : Sendable {

extension SwiftModuleTwoMessage : ProtoDefaultedValue {

public static var defaultedValue: SwiftModuleTwoMessage {
SwiftModuleTwoMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -125,8 +125,8 @@ extension SwiftModuleTwoMessage.NestedMessage : Sendable {

extension SwiftModuleTwoMessage.NestedMessage : ProtoDefaultedValue {

public static var defaultedValue: SwiftModuleTwoMessage.NestedMessage {
SwiftModuleTwoMessage.NestedMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
4 changes: 2 additions & 2 deletions wire-tests-swift/no-manifest/src/main/swift/AllTypes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1978,8 +1978,8 @@ extension AllTypes.NestedMessage : Sendable {

extension AllTypes.NestedMessage : ProtoDefaultedValue {

public static var defaultedValue: AllTypes.NestedMessage {
AllTypes.NestedMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ extension DeprecatedProto : Sendable {

extension DeprecatedProto : ProtoDefaultedValue {

public static var defaultedValue: DeprecatedProto {
DeprecatedProto()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ extension EmbeddedMessage : Sendable {

extension EmbeddedMessage : ProtoDefaultedValue {

public static var defaultedValue: EmbeddedMessage {
EmbeddedMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension ExternalMessage : Sendable {

extension ExternalMessage : ProtoDefaultedValue {

public static var defaultedValue: ExternalMessage {
ExternalMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
12 changes: 6 additions & 6 deletions wire-tests-swift/no-manifest/src/main/swift/FooBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ extension FooBar : Sendable {

extension FooBar : ProtoDefaultedValue {

public static var defaultedValue: FooBar {
FooBar()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -256,8 +256,8 @@ extension FooBar.Nested : Sendable {

extension FooBar.Nested : ProtoDefaultedValue {

public static var defaultedValue: FooBar.Nested {
FooBar.Nested()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -325,8 +325,8 @@ extension FooBar.More : Sendable {

extension FooBar.More : ProtoDefaultedValue {

public static var defaultedValue: FooBar.More {
FooBar.More()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension ForeignMessage : Sendable {

extension ForeignMessage : ProtoDefaultedValue {

public static var defaultedValue: ForeignMessage {
ForeignMessage()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
52 changes: 26 additions & 26 deletions wire-tests-swift/no-manifest/src/main/swift/Form.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ extension Form : Sendable {

extension Form : ProtoDefaultedValue {

public static var defaultedValue: Form {
Form()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -436,8 +436,8 @@ extension Form.ButtonElement : Sendable {

extension Form.ButtonElement : ProtoDefaultedValue {

public static var defaultedValue: Form.ButtonElement {
Form.ButtonElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -492,8 +492,8 @@ extension Form.LocalImageElement : Sendable {

extension Form.LocalImageElement : ProtoDefaultedValue {

public static var defaultedValue: Form.LocalImageElement {
Form.LocalImageElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -548,8 +548,8 @@ extension Form.RemoteImageElement : Sendable {

extension Form.RemoteImageElement : ProtoDefaultedValue {

public static var defaultedValue: Form.RemoteImageElement {
Form.RemoteImageElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -604,8 +604,8 @@ extension Form.MoneyElement : Sendable {

extension Form.MoneyElement : ProtoDefaultedValue {

public static var defaultedValue: Form.MoneyElement {
Form.MoneyElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -660,8 +660,8 @@ extension Form.SpacerElement : Sendable {

extension Form.SpacerElement : ProtoDefaultedValue {

public static var defaultedValue: Form.SpacerElement {
Form.SpacerElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -716,8 +716,8 @@ extension Form.TextElement : Sendable {

extension Form.TextElement : ProtoDefaultedValue {

public static var defaultedValue: Form.TextElement {
Form.TextElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -785,8 +785,8 @@ extension Form.CustomizedCardElement : Sendable {

extension Form.CustomizedCardElement : ProtoDefaultedValue {

public static var defaultedValue: Form.CustomizedCardElement {
Form.CustomizedCardElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -841,8 +841,8 @@ extension Form.AddressElement : Sendable {

extension Form.AddressElement : ProtoDefaultedValue {

public static var defaultedValue: Form.AddressElement {
Form.AddressElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -897,8 +897,8 @@ extension Form.TextInputElement : Sendable {

extension Form.TextInputElement : ProtoDefaultedValue {

public static var defaultedValue: Form.TextInputElement {
Form.TextInputElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -953,8 +953,8 @@ extension Form.OptionPickerElement : Sendable {

extension Form.OptionPickerElement : ProtoDefaultedValue {

public static var defaultedValue: Form.OptionPickerElement {
Form.OptionPickerElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -1009,8 +1009,8 @@ extension Form.DetailRowElement : Sendable {

extension Form.DetailRowElement : ProtoDefaultedValue {

public static var defaultedValue: Form.DetailRowElement {
Form.DetailRowElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down Expand Up @@ -1065,8 +1065,8 @@ extension Form.CurrencyConversionFlagsElement : Sendable {

extension Form.CurrencyConversionFlagsElement : ProtoDefaultedValue {

public static var defaultedValue: Form.CurrencyConversionFlagsElement {
Form.CurrencyConversionFlagsElement()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
4 changes: 2 additions & 2 deletions wire-tests-swift/no-manifest/src/main/swift/Mappy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ extension Mappy : Sendable {

extension Mappy : ProtoDefaultedValue {

public static var defaultedValue: Mappy {
Mappy()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
4 changes: 2 additions & 2 deletions wire-tests-swift/no-manifest/src/main/swift/MappyTwo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ extension MappyTwo : Sendable {

extension MappyTwo : ProtoDefaultedValue {

public static var defaultedValue: MappyTwo {
MappyTwo()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ extension MessageUsingMultipleEnums : Sendable {

extension MessageUsingMultipleEnums : ProtoDefaultedValue {

public static var defaultedValue: MessageUsingMultipleEnums {
MessageUsingMultipleEnums()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension MessageWithOptions : Sendable {

extension MessageWithOptions : ProtoDefaultedValue {

public static var defaultedValue: MessageWithOptions {
MessageWithOptions()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ extension MessageWithStatus : Sendable {

extension MessageWithStatus : ProtoDefaultedValue {

public static var defaultedValue: MessageWithStatus {
MessageWithStatus()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ extension ModelEvaluation : Sendable {

extension ModelEvaluation : ProtoDefaultedValue {

public static var defaultedValue: ModelEvaluation {
ModelEvaluation()
public static var defaultedValue: Self {
.init()
}
}

Expand Down
Loading

0 comments on commit f7a44ab

Please sign in to comment.