-
Notifications
You must be signed in to change notification settings - Fork 114
[swift2objc] feat: Generate implicit constructors for Swift structs #2940
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
Merged
liamappelbe
merged 2 commits into
dart-lang:main
from
Hassnaa9:fix/implicit-struct-initializers
Feb 17, 2026
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
pkgs/swift2objc/test/integration/implicit_initializers_input.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| public struct MyPerson { | ||
| public var name: String | ||
| public var age: Int | ||
| } | ||
|
|
||
| public struct MyConfig { | ||
| public var title: String | ||
| public var count: Int | ||
| public var enabled: Bool | ||
| } | ||
|
|
||
| public struct MyCustomStruct { | ||
| public var data: Int | ||
|
|
||
| public init(value: Int) { | ||
| self.data = value * 2 | ||
| } | ||
| } | ||
|
|
||
| public struct MyStaticStruct { | ||
| public static var defaultName = "Default" | ||
| public var name: String | ||
| } | ||
|
|
||
| public struct MyComputedStruct { | ||
| public var firstName: String | ||
| public var lastName: String | ||
| public var fullName: String { | ||
| return "\(firstName) \(lastName)" | ||
| } | ||
| } |
165 changes: 165 additions & 0 deletions
165
pkgs/swift2objc/test/integration/implicit_initializers_output.swift
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,165 @@ | ||
| // Test preamble text | ||
|
|
||
| import Foundation | ||
|
|
||
| @objc public class MyCustomStructWrapper: NSObject { | ||
| var wrappedInstance: MyCustomStruct | ||
|
|
||
| @objc public var data: Int { | ||
| get { | ||
| wrappedInstance.data | ||
| } | ||
| set { | ||
| wrappedInstance.data = newValue | ||
| } | ||
| } | ||
|
|
||
| init(_ wrappedInstance: MyCustomStruct) { | ||
| self.wrappedInstance = wrappedInstance | ||
| } | ||
|
|
||
| @objc public init(value: Int) { | ||
| wrappedInstance = MyCustomStruct(value: value) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @objc public class MyStaticStructWrapper: NSObject { | ||
| var wrappedInstance: MyStaticStruct | ||
|
|
||
| @objc static public var defaultName: String { | ||
| get { | ||
| MyStaticStruct.defaultName | ||
| } | ||
| set { | ||
| MyStaticStruct.defaultName = newValue | ||
| } | ||
| } | ||
|
|
||
| @objc public var name: String { | ||
| get { | ||
| wrappedInstance.name | ||
| } | ||
| set { | ||
| wrappedInstance.name = newValue | ||
| } | ||
| } | ||
|
|
||
| init(_ wrappedInstance: MyStaticStruct) { | ||
| self.wrappedInstance = wrappedInstance | ||
| } | ||
|
|
||
| @objc public init(name: String) { | ||
| wrappedInstance = MyStaticStruct(name: name) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @objc public class MyComputedStructWrapper: NSObject { | ||
| var wrappedInstance: MyComputedStruct | ||
|
|
||
| @objc public var fullName: String { | ||
| get { | ||
| wrappedInstance.fullName | ||
| } | ||
| } | ||
|
|
||
| @objc public var lastName: String { | ||
| get { | ||
| wrappedInstance.lastName | ||
| } | ||
| set { | ||
| wrappedInstance.lastName = newValue | ||
| } | ||
| } | ||
|
|
||
| @objc public var firstName: String { | ||
| get { | ||
| wrappedInstance.firstName | ||
| } | ||
| set { | ||
| wrappedInstance.firstName = newValue | ||
| } | ||
| } | ||
|
|
||
| init(_ wrappedInstance: MyComputedStruct) { | ||
| self.wrappedInstance = wrappedInstance | ||
| } | ||
|
|
||
| @objc public init(firstName: String, lastName: String) { | ||
| wrappedInstance = MyComputedStruct(firstName: firstName, lastName: lastName) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @objc public class MyConfigWrapper: NSObject { | ||
| var wrappedInstance: MyConfig | ||
|
|
||
| @objc public var count: Int { | ||
| get { | ||
| wrappedInstance.count | ||
| } | ||
| set { | ||
| wrappedInstance.count = newValue | ||
| } | ||
| } | ||
|
|
||
| @objc public var title: String { | ||
| get { | ||
| wrappedInstance.title | ||
| } | ||
| set { | ||
| wrappedInstance.title = newValue | ||
| } | ||
| } | ||
|
|
||
| @objc public var enabled: Bool { | ||
| get { | ||
| wrappedInstance.enabled | ||
| } | ||
| set { | ||
| wrappedInstance.enabled = newValue | ||
| } | ||
| } | ||
|
|
||
| init(_ wrappedInstance: MyConfig) { | ||
| self.wrappedInstance = wrappedInstance | ||
| } | ||
|
|
||
| @objc public init(title: String, count: Int, enabled: Bool) { | ||
| wrappedInstance = MyConfig(title: title, count: count, enabled: enabled) | ||
| } | ||
|
|
||
| } | ||
|
|
||
| @objc public class MyPersonWrapper: NSObject { | ||
| var wrappedInstance: MyPerson | ||
|
|
||
| @objc public var age: Int { | ||
| get { | ||
| wrappedInstance.age | ||
| } | ||
| set { | ||
| wrappedInstance.age = newValue | ||
| } | ||
| } | ||
|
|
||
| @objc public var name: String { | ||
| get { | ||
| wrappedInstance.name | ||
| } | ||
| set { | ||
| wrappedInstance.name = newValue | ||
| } | ||
| } | ||
|
|
||
| init(_ wrappedInstance: MyPerson) { | ||
| self.wrappedInstance = wrappedInstance | ||
| } | ||
|
|
||
| @objc public init(name: String, age: Int) { | ||
| wrappedInstance = MyPerson(name: name, age: age) | ||
| } | ||
|
|
||
| } | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.