Skip to content

Build error when introducing new swift code to hello-swift-java hashing-lib #15

@gevartosky

Description

@gevartosky

Steps to reproduce:

  1. Download the project and follow the install instructions
  2. Make sure hello-swift-java-hashing-app builds successfully on Android Studio
  3. Add the following code
public enum CustomerSupportStoreAction: Sendable {
    case fetchProfile
    case setAccountName(String)
}

OR

public struct CustomerSupportState: Sendable {
    public var accountTierName: String?
    public var priorityTierColor: String?
    public var isLoggedIn: Bool

    public init(accountTierName: String?, priorityTierColor: String?, isLoggedIn: Bool) {
        self.accountTierName = accountTierName
        self.priorityTierColor = priorityTierColor
        self.isLoggedIn = isLoggedIn
    }
}
  1. Delete the folder .build inside hashing-lib otherwise Android studio won't pick up the swift changes
  2. Build hello-swift-java-hashing-app again from Android Studio

The following error is thrown

[700/703] Compiling SwiftHashing SwiftHashing+SwiftJava.swift
/Users/gregorio/Downloads/swift-android-examples-main/hello-swift-java/hashing-lib/.build/plugins/outputs/hashing-lib/SwiftHashing/destination/JExtractSwiftPlugin/Sources/SwiftHashing+SwiftJava.swift:63:10: error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
61 |   let method$ = _JNIMethodIDCache.Method(name: "<init>", signature: "(Ljava/lang/String;)V")
62 |   let constructorID$ = cache$[method$]
63 |   return withVaList([_0.getJNIValue(in: environment!) ?? 0]) {
   |          `- error: failed to produce diagnostic for expression; please submit a bug report (https://swift.org/contributing/#reporting-bugs)
64 |     return environment.interface.NewObjectV(environment, class$, constructorID$, $0)
65 |   }

The function where the error is reported

@_cdecl("Java_com_example_swifthashing_CustomerSupportStoreAction__00024getAsSetProfile__J")
func Java_com_example_swifthashing_CustomerSupportStoreAction__00024getAsSetProfile__J(environment: UnsafeMutablePointer<JNIEnv?>!, thisClass: jclass, self: jlong) -> jobject? {
  assert(self != 0, "self memory address was null")
  let selfBits$ = Int(Int64(fromJNI: self, in: environment!))
  let self$ = UnsafeMutablePointer<CustomerSupportStoreAction>(bitPattern: selfBits$)
  guard let self$ else {
    fatalError("self memory address was null in call to \(#function)!")
  }
  guard case .setProfile(let _0) = self$.pointee else {
    fatalError("Expected enum case 'setProfile', but was '\(self$.pointee)'!")
  }
  let cache$ = _JNI_CustomerSupportStoreAction.customerSupportStoreActionSetProfileCache
  let class$ = cache$.javaClass
  let method$ = _JNIMethodIDCache.Method(name: "<init>", signature: "(Ljava/lang/String;)V")
  let constructorID$ = cache$[method$]
  return withVaList([_0.getJNIValue(in: environment!) ?? 0]) {
    return environment.interface.NewObjectV(environment, class$, constructorID$, $0)
  }
} // printCDecl(_:javaMethodName:parentName:parameters:resultType:_:) @ JExtractSwiftLib/JNISwift2JavaGenerator+SwiftThunkPrinting.swift:439

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions