From 10d6a8f0778653ba6671bae9ff08aba017dac4ec Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 2 Aug 2021 10:26:34 +0200 Subject: [PATCH] Fix docs of Reflect.Symbol.children Fixes #13230 --- library/src/scala/quoted/Quotes.scala | 2 +- tests/run-macros/i13230.check | 1 + tests/run-macros/i13230/Macros_1.scala | 12 ++++++++++++ tests/run-macros/i13230/Test_2.scala | 1 + 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/run-macros/i13230.check create mode 100644 tests/run-macros/i13230/Macros_1.scala create mode 100644 tests/run-macros/i13230/Test_2.scala diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index e3a4075e6821..4a0b2eae3817 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -3690,7 +3690,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => /** The symbol of the companion module */ def companionModule: Symbol - /** Case class or case object children of a sealed trait */ + /** Case class or case object children of a sealed trait or cases of an `enum`. */ def children: List[Symbol] end extension } diff --git a/tests/run-macros/i13230.check b/tests/run-macros/i13230.check new file mode 100644 index 000000000000..01b246fb33f6 --- /dev/null +++ b/tests/run-macros/i13230.check @@ -0,0 +1 @@ +List((A,E), (B,E)) diff --git a/tests/run-macros/i13230/Macros_1.scala b/tests/run-macros/i13230/Macros_1.scala new file mode 100644 index 000000000000..424358e83b1a --- /dev/null +++ b/tests/run-macros/i13230/Macros_1.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +enum E: + case A, B + +inline def showEnumChildren = ${ showEnumChildrenExpr } + +def showEnumChildrenExpr(using Quotes) = + import quotes.reflect.* + val repr = TypeRepr.of[E] + Expr(TypeRepr.of[E].classSymbol.get.children.map(sym => (sym.name, repr.memberType(sym).show))) + diff --git a/tests/run-macros/i13230/Test_2.scala b/tests/run-macros/i13230/Test_2.scala new file mode 100644 index 000000000000..23f582ac9c94 --- /dev/null +++ b/tests/run-macros/i13230/Test_2.scala @@ -0,0 +1 @@ +@main def Test = println(showEnumChildren)