-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #18484: Query every legal child of sealed class on children call
Sometimes, a macro or Mirror can be called/generated for a type that may have not had its children registered by natural typechecking procedures of the compiler. This meant that, in those cases, the Mirror could not have been generated correctly, and macro could not obtain the children of the class. This was partially fixed in a previous PR by introducing a separate procedure for querying children, outside of the regular typechecking procedure. However, they was only queried in the owner symbol or in the companion class, when non-enum sealed classes specifically, can appear anywhere in the file. This commit aims to rectify this by searching for any class that appears in the same file as the sealed type.
- Loading branch information
Showing
3 changed files
with
47 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
object Macro { | ||
import scala.quoted.* | ||
|
||
def subtypesImpl[A: Type](using quotes: Quotes): Expr[String] = { | ||
import quotes.reflect.* | ||
val a = TypeRepr.of[A].typeSymbol.children | ||
'{""} | ||
} | ||
|
||
inline def subtypes[A]: String = ${ subtypesImpl[A] } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
class Test { | ||
def test(): Unit = { | ||
scala.compiletime.testing.typeCheckErrors("Macro.subtypes[top.inner.Inner.Shape]") | ||
} | ||
} | ||
|
||
package top { | ||
package inner { | ||
object Inner: | ||
sealed trait Shape | ||
case class Circle(center: Int, rad: Double) extends Shape | ||
object Inner2: | ||
case class Circle2(center: Int, rad: Double) extends Shape | ||
} | ||
case class Circle3(center: Int, rad: Double) extends inner.Inner.Shape | ||
} | ||
case class Circle4(center: Int, rad: Double) extends top.inner.Inner.Shape | ||
|
||
package top2 { | ||
case class Circle5(center: Int, rad: Double) extends top.inner.Inner.Shape | ||
} |