Skip to content

Commit

Permalink
Merge pull request #409 from sjrd/java-interface-ctor
Browse files Browse the repository at this point in the history
Fix #407: Synthesize a constructor for Java interfaces.
  • Loading branch information
sjrd authored Nov 30, 2023
2 parents 1aca135 + 56c7da0 commit e3f97f7
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,18 @@ private[reader] object ClassfileParser {
else if cls.isString then rctx.createStringMagicMethods(cls)
else if cls.isJavaEnum then rctx.createEnumMagicMethods(cls)

// Synthesize a constructor for interfaces
if cls.isTrait then
val ctor = TermSymbol
.create(nme.Constructor, cls)
.withDeclaredType(cls.makePolyConstructorType(MethodType(Nil, Nil, rctx.UnitType)))
.withFlags(Method | JavaDefined, None)
.setAnnotations(Nil)
.autoFillParamSymss()
ctor.paramSymss.foreach(_.merge.foreach(_.setAnnotations(Nil)))
allRegisteredSymbols += ctor
end if

loadMembers()

val annotations = readAnnotations(cls, attributes)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package simple_trees

class ClassExtendsJavaInterface extends javadefined.JavaInterface1()
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package simple_trees

class ClassExtendsPolyJavaInterface extends java.util.function.Predicate[String]():
def test(t: String): Boolean = t.isEmpty()
end ClassExtendsPolyJavaInterface

0 comments on commit e3f97f7

Please sign in to comment.