Skip to content

Commit

Permalink
Merge pull request #381 from sjrd/fix-java-lang-enum-ctor
Browse files Browse the repository at this point in the history
Fix #380: Give the correct type to the synthetic ctor of j.l.Enum.
  • Loading branch information
sjrd authored Nov 8, 2023
2 parents 7eda22a + 67e741d commit bad2ee2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,8 @@ final class Definitions private[tastyquery] (ctx: Context, rootPackage: PackageS
lazy val String_+ : TermSymbol = StringClass.findNonOverloadedDecl(nme.m_+)

private[tastyquery] def createEnumMagicMethods(cls: ClassSymbol): Unit =
createSpecialMethod(cls, nme.Constructor, PolyType(List(typeName("E")), List(NothingAnyBounds), UnitType))
val ctorTpe = PolyType(List(typeName("E")), List(NothingAnyBounds), MethodType(Nil, Nil, UnitType))
createSpecialMethod(cls, nme.Constructor, ctorTpe)
end createEnumMagicMethods

/** Creates the members that are patched from stdLibPatches on Predef.
Expand Down
11 changes: 11 additions & 0 deletions tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2395,6 +2395,17 @@ class TypeSuite extends UnrestrictedUnpicklingSuite {
assert(clue(app.tpe).isRef(anonClassSym))
}

testWithContext("java-enum") {
val JavaLangEnumClass = ctx.findTopLevelClass("java.lang.Enum")
val JavaEnumClass = ctx.findTopLevelClass("simple_trees.JavaEnum")

val tree = JavaEnumClass.tree.get

findTree(tree.rhs.parents.head) { case apply: Apply =>
assert(clue(apply.tpe).isApplied(_.isRef(JavaLangEnumClass), List(_.isRef(JavaEnumClass))))
}
}

testWithContext("toplevel-module-class-with-opaque-type-alias-companion-signature-name") {
val TopLevelOpaqueTypeAliasModule =
ctx.findStaticTerm("crosspackagetasty.TopLevelOpaqueTypeAlias$package.TopLevelOpaqueTypeAlias")
Expand Down
5 changes: 5 additions & 0 deletions test-sources/src/main/scala/simple_trees/JavaEnum.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package simple_trees

enum JavaEnum extends java.lang.Enum[JavaEnum]():
case Foo, Bar
end JavaEnum

0 comments on commit bad2ee2

Please sign in to comment.