From 67e741d6d0cbec841ec022b979c6ad01eff17651 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Doeraene?= Date: Wed, 8 Nov 2023 15:53:09 +0100 Subject: [PATCH] Fix #380: Give the correct type to the synthetic ctor of j.l.Enum. --- .../src/main/scala/tastyquery/Definitions.scala | 3 ++- .../shared/src/test/scala/tastyquery/TypeSuite.scala | 11 +++++++++++ .../src/main/scala/simple_trees/JavaEnum.scala | 5 +++++ 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 test-sources/src/main/scala/simple_trees/JavaEnum.scala diff --git a/tasty-query/shared/src/main/scala/tastyquery/Definitions.scala b/tasty-query/shared/src/main/scala/tastyquery/Definitions.scala index 17cec2e6..f8af43a5 100644 --- a/tasty-query/shared/src/main/scala/tastyquery/Definitions.scala +++ b/tasty-query/shared/src/main/scala/tastyquery/Definitions.scala @@ -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. diff --git a/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala b/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala index d1a0ec3d..20ab2f25 100644 --- a/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala +++ b/tasty-query/shared/src/test/scala/tastyquery/TypeSuite.scala @@ -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") diff --git a/test-sources/src/main/scala/simple_trees/JavaEnum.scala b/test-sources/src/main/scala/simple_trees/JavaEnum.scala new file mode 100644 index 00000000..509efcb0 --- /dev/null +++ b/test-sources/src/main/scala/simple_trees/JavaEnum.scala @@ -0,0 +1,5 @@ +package simple_trees + +enum JavaEnum extends java.lang.Enum[JavaEnum](): + case Foo, Bar +end JavaEnum