forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
29 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
trait Statement | ||
trait Definition extends Statement | ||
|
||
trait ClassDef extends Definition: | ||
def constructor: DefDef | ||
|
||
object ClassDef: | ||
def copy(constr: DefDef): ClassDef = ??? | ||
|
||
// >>> This abstract implementation of DefDef causes a compilation error in transform... | ||
type DefDef <: Definition | ||
val DefDef: DefDefModule = ??? | ||
trait DefDefModule: | ||
def unapply(ddef: DefDef): (String, List[AnyRef]) | ||
// ...unless this given TypeTest is commented out, in which case we get only a type test warning | ||
given scala.reflect.TypeTest[Statement, DefDef] = ??? | ||
|
||
// >>> This alternative works | ||
// trait DefDef extends Definition | ||
// object DefDef: | ||
// def unapply(ddef: DefDef): (String, List[AnyRef]) = ??? | ||
|
||
// >>> This alternative also works | ||
// case class DefDef(name: String, paramss: List[AnyRef]) extends Definition | ||
|
||
def transform(tree: Statement): Statement = tree match | ||
case tree: ClassDef => | ||
val constructor @ DefDef(_, _) = transform(tree.constructor): @unchecked | ||
ClassDef.copy(constructor) |