swiftlang / swiftlang/swift-java

Protocols with default methods in extension fail to compile

Open
#562 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Swift
Stars
1.2k
Forks
123
Avg merge
1d 7h
Merged PRs (30d)
16

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the analysis phase and extracted interface generation described in the issue, then reproduce the protocol and extension example. Trace how protocol requirements are distinguished from declarations in extensions; done means the example compiles without treating the extension method as an abstract interface requirement, with extension declarations represented according to the intended default-method behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, swift
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.