swiftlang / swiftlang/swift-java
Protocols with default methods in extension fail to compile
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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