Skip to content

Protocols with default methods in extension fail to compile #562

Open

Description

@madsodgaard

If you have a protocol which has a default method implemented in an extension, the generated code will fail to compile because the Java compiler will complain about the extracted interface "is not abstract and does not override abstract method".

Consider the following

protocol MyProtocol {}

extension MyProtocol {
  public func myDefaultMethod() {}
}

will fail with:

error: MyProtocol is not abstract and does not override abstract method myDefaultMethod() in MyProtocol

Instead we should not generate any methods, variables and initializers defined in extensions as part of the extracted interface. But we could generate them as default methods instead. This means we need to change the analysis phase to know what decls are defined in an extension and which come from the protocol requirements themselves.

Activity

  1. ktoso commented on Feb 13, 2026

    @ktoso
    Collaborator

    Agreed, default methods is the way to go here. Thanks for reporting! Will you take a stab at it?

  2. teamhimeh commented on Nov 4, 2026

    @teamhimeh

    I faced almost the same issue and did a workaround in my fork. qoncept#2
    Will #934 solve this issue?

  3. Hokila commented on Nov 4, 2026

    @Hokila
    Contributor

    #934 should fix the compilation error here.

    It doesn't generate Java 8 default methods that forward to Swift implementations, though. My main goal in #934 was fixing the duplicate thunk issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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