-
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 checks for the consistency of the parents in TreeChecker
- Loading branch information
1 parent
95266f2
commit b7ccb11
Showing
9 changed files
with
133 additions
and
14 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
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,22 @@ | ||
|
||
-- Error: tests/neg-macros/i18677-a/Test_2.scala:4:6 ------------------------------------------------------------------- | ||
3 |@extendFoo | ||
4 |class AFoo // error | ||
|^ | ||
|Malformed tree was found while expanding macro with -Xcheck-macros. | ||
|The tree does not conform to the compiler's tree invariants. | ||
| | ||
|Macro was: | ||
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo() | ||
| | ||
|The macro returned: | ||
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-a/Test_2.scala") @extendFoo class AFoo() extends Foo | ||
| | ||
|Error: | ||
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo | ||
| | ||
|Parents in symbol: [class Object] | ||
|Parents in tree: [trait Foo] | ||
| | ||
| | ||
|stacktrace available when compiling with `-Ydebug` |
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,18 @@ | ||
//> using -expermiental | ||
|
||
import annotation.MacroAnnotation | ||
import quoted.* | ||
|
||
trait Foo | ||
|
||
class extendFoo extends MacroAnnotation : | ||
override def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = | ||
import quotes.reflect.* | ||
tree match | ||
case ClassDef(name, ctr, p, self, body) => | ||
val parents = List(TypeTree.of[Foo]) | ||
val newTree = ClassDef.copy(tree)(name, ctr, parents, self, body) | ||
newTree :: Nil | ||
case _ => | ||
report.error("@extendFoo can only annotate class definitions") | ||
tree :: Nil |
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,4 @@ | ||
//> using -expermiental | ||
|
||
@extendFoo | ||
class AFoo // error |
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,22 @@ | ||
|
||
-- Error: tests/neg-macros/i18677-b/Test_2.scala:4:6 ------------------------------------------------------------------- | ||
3 |@extendFoo | ||
4 |class AFoo // error | ||
|^ | ||
|Malformed tree was found while expanding macro with -Xcheck-macros. | ||
|The tree does not conform to the compiler's tree invariants. | ||
| | ||
|Macro was: | ||
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo() | ||
| | ||
|The macro returned: | ||
|@scala.annotation.internal.SourceFile("tests/neg-macros/i18677-b/Test_2.scala") @extendFoo class AFoo() extends Foo | ||
| | ||
|Error: | ||
|assertion failed: Parents of class symbol differs from the parents in the tree for class AFoo | ||
| | ||
|Parents in symbol: [class Object] | ||
|Parents in tree: [class Foo] | ||
| | ||
| | ||
|stacktrace available when compiling with `-Ydebug` |
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,18 @@ | ||
//> using -expermiental | ||
|
||
import annotation.MacroAnnotation | ||
import quoted.* | ||
|
||
class Foo | ||
|
||
class extendFoo extends MacroAnnotation : | ||
override def transform(using Quotes)(tree: quotes.reflect.Definition): List[quotes.reflect.Definition] = | ||
import quotes.reflect.* | ||
tree match | ||
case ClassDef(name, ctr, p, self, body) => | ||
val parents = List(TypeTree.of[Foo]) | ||
val newTree = ClassDef.copy(tree)(name, ctr, parents, self, body) | ||
newTree :: Nil | ||
case _ => | ||
report.error("@extendFoo can only annotate class definitions") | ||
tree :: Nil |
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,4 @@ | ||
//> using -expermiental | ||
|
||
@extendFoo | ||
class AFoo // error |
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