-
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.
Add a check for correct Array shape in quotes.reflect.ClassOfConstant (…
…#22033) Closes #21916 I tried to supply the ClassOfConstant with multiple other broken Types, but I was unable to break it beyond the linked issue, so I ended up adding the check for only that one case. This makes sense - the backend (and thus erasure) needs to know if the Array type parameter is a primitive type, but in other cases the erasure phase needs to know only the class, without the type parameters. It's impossible to call classOf through the quoted code (`'{classOf[t]}` with a boundless t will error out), so we don't need that additional check there. There does appear to be an issue with being able to set `'{List[Array]}` resulting in a crash, but that is beyond the scope of this fix - I will prepare a separate issue for that (edit: reported [here](#22034)).
- Loading branch information
Showing
4 changed files
with
38 additions
and
1 deletion.
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,15 @@ | ||
|
||
-- Error: tests/neg-macros/i21916/Test_2.scala:3:27 -------------------------------------------------------------------- | ||
3 |@main def Test = Macro.test() // error | ||
| ^^^^^^^^^^^^ | ||
| Exception occurred while executing macro expansion. | ||
| java.lang.AssertionError: Illegal empty Array type constructor. Please supply a type parameter. | ||
| at Macro$.testImpl(Macro_1.scala:8) | ||
| | ||
|--------------------------------------------------------------------------------------------------------------------- | ||
|Inline stack trace | ||
|- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||
|This location contains code that was inlined from Macro_1.scala:3 | ||
3 | inline def test() = ${testImpl} | ||
| ^^^^^^^^^^^ | ||
--------------------------------------------------------------------------------------------------------------------- |
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,9 @@ | ||
import scala.quoted._ | ||
object Macro: | ||
inline def test() = ${testImpl} | ||
def testImpl(using Quotes): Expr[Any] = { | ||
import quotes.reflect._ | ||
val tpe = TypeRepr.of[Array[Byte]] match | ||
case AppliedType(tycons, _) => tycons | ||
Literal(ClassOfConstant(tpe)).asExpr | ||
} |
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,3 @@ | ||
// lack of type ascription is on purpose, | ||
// as that was part of what would cause the crash before. | ||
@main def Test = Macro.test() // error |