-
-
Save MrLotU/a3ec8857871ee516a5bd36227976c7e7 to your computer and use it in GitHub Desktop.
This file contains 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
protocol Commands { } | |
extension Command: Commands { } | |
@_functionBuilder | |
struct CommandsBuilder: Commands { | |
static func buildBlock(_ commands: Command...) -> CommandList { | |
return CommandList(commands: { commands }) | |
} | |
static func buildExpression(_ commands: Command...) -> CommandList { | |
return CommandList(commands: { commands }) | |
} | |
} | |
@_functionBuilder | |
struct CommandListBuilder: Commands { | |
static func buildBlock(_ commands: Command...) -> [Command] { | |
return commands | |
} | |
} | |
struct CommandList: Commands { | |
var commands: [Command] | |
init(@CommandListBuilder commands: () -> [Command]) { | |
self.commands = commands() | |
} | |
} | |
protocol Plugin { | |
associatedtype C: Commands | |
// var otherCommands: () -> Commands { get } | |
var commands: C { get } | |
} | |
struct PluginOne: Plugin { | |
@CommandsBuilder | |
var commands: some Commands { | |
// Error here | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
struct PluginTwo: Plugin { | |
var commands: some Commands { | |
// Works | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
struct PluginThree: Plugin { | |
var commands: some Commands { | |
// Works | |
CommandList { | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
} |
This file contains 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
protocol Commands { } | |
extension Command: Commands { } | |
@_functionBuilder | |
struct CommandsBuilder: Commands { | |
static func buildBlock(_ commands: Command...) -> CommandList { | |
return CommandList(commands: { commands }) | |
} | |
static func buildExpression(_ commands: Command...) -> CommandList { | |
return CommandList(commands: { commands }) | |
} | |
} | |
@_functionBuilder | |
struct CommandListBuilder: Commands { | |
static func buildBlock(_ commands: Command...) -> [Command] { | |
return commands | |
} | |
} | |
struct CommandList: Commands { | |
var commands: [Command] | |
init(@CommandListBuilder commands: () -> [Command]) { | |
self.commands = commands() | |
} | |
} | |
protocol Plugin { | |
associatedtype C: Commands | |
var commands: C { get } | |
} | |
@available(OSX 10.15.0, *) | |
struct PluginOne: Plugin { | |
@CommandsBuilder | |
var commands: some Commands { | |
// Error here. Cannot convert return expression of type 'CommandList' to return type 'some Commands' | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
@available(OSX 10.15.0, *) | |
struct PluginTwo: Plugin { | |
var commands: some Commands { | |
// Works | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
@available(OSX 10.15.0, *) | |
struct PluginThree: Plugin { | |
var commands: some Commands { | |
// Works | |
CommandList { | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
Command(trigger: "abc", arguments: [], aliases: [], group: nil, permissionChecks: [], userInfo: [:]) { (_, _, _) in | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment