Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@
public protocol ProtocolWithStatic {
// static requirements are not yet supported.
static func myFunc() -> Int
static var value: Int64 { get }
init()
}

public func useProtocolWithStatic(_ value: any ProtocolWithStatic) -> Int {
let meta = type(of: value)
return meta.myFunc()
}

public protocol ProtocolWithStaticProperty {
static var value: Int { get }
}

public func useProtocolWithStaticProperty(_ value: any ProtocolWithStaticProperty) -> Int {
let meta = type(of: value)
return meta.value
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension JNISwift2JavaGenerator {
) -> [ImportedNominalType: JavaInterfaceSwiftWrapper] {
var wrappers = [ImportedNominalType: JavaInterfaceSwiftWrapper]()

for type in types {
for type in types where type.swiftNominal.kind == .protocol {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed that JavaInterfaceProtocolWrapperGenerator was being used for all types erroneously.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, nice catch

do {
let translator = JavaInterfaceProtocolWrapperGenerator()
wrappers[type] = try translator.generate(for: type)
Expand Down Expand Up @@ -78,6 +78,12 @@ extension JNISwift2JavaGenerator {

struct JavaInterfaceProtocolWrapperGenerator {
func generate(for type: ImportedNominalType) throws -> JavaInterfaceSwiftWrapper {
if !type.initializers.isEmpty
|| type.methods.contains(where: \.isStatic)
|| type.variables.contains(where: \.isStatic) {
throw JavaTranslationError.protocolStaticRequirementsNotSupported
}

let functions = try type.methods.map { method in
try translate(function: method)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,8 @@ extension JNISwift2JavaGenerator {
// FIXME: Remove once we support protocol variables
case protocolVariablesNotSupported

case protocolStaticRequirementsNotSupported

/// We cannot generate interface wrappers for
/// protocols that we unable to be jextracted.
case protocolWasNotExtracted
Expand Down
Loading