Skip to content

Commit 7813d66

Browse files
committed
fixes resetAttrs
1 parent 8ce8690 commit 7813d66

File tree

6 files changed

+17
-22
lines changed

6 files changed

+17
-22
lines changed

src/compiler/scala/reflect/makro/runtime/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ trait Typers {
6969
def unapply(error: TypeError): Option[(Position, String)] = Some((error.pos, error.msg))
7070
}
7171

72-
def resetAllAttrs[T <: Tree](tree: T): T = mirror.resetAllAttrs(tree)
72+
def resetAllAttrs(tree: Tree): Tree = mirror.resetAllAttrs(tree)
7373

74-
def resetLocalAttrs[T <: Tree](tree: T): T = mirror.resetLocalAttrs(tree)
74+
def resetLocalAttrs(tree: Tree): Tree = mirror.resetLocalAttrs(tree)
7575
}

src/compiler/scala/reflect/runtime/ToolBoxes.scala

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -315,18 +315,16 @@ trait ToolBoxes extends { self: Universe =>
315315
// todo. implement this
316316
???
317317

318-
def resetAllAttrs[T <: Tree](tree: T): T = {
318+
def resetAllAttrs(tree: Tree): Tree = {
319319
val ctree: compiler.Tree = importer.importTree(tree)
320320
val ttree: compiler.Tree = compiler.resetAllAttrs(ctree)
321-
val rmttree = exporter.importTree(ttree)
322-
rmttree.asInstanceOf[T]
321+
exporter.importTree(ttree)
323322
}
324323

325-
def resetLocalAttrs[T <: Tree](tree: T): T = {
324+
def resetLocalAttrs(tree: Tree): Tree = {
326325
val ctree: compiler.Tree = importer.importTree(tree)
327326
val ttree: compiler.Tree = compiler.resetLocalAttrs(ctree)
328-
val rmttree = exporter.importTree(ttree)
329-
rmttree.asInstanceOf[T]
327+
exporter.importTree(ttree)
330328
}
331329

332330
def showAttributed(tree: Tree, printTypes: Boolean = true, printIds: Boolean = true, printKinds: Boolean = false): String =

src/compiler/scala/tools/nsc/ToolBoxes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ trait ToolBoxes { self: Global =>
3030
// todo. implement this
3131
???
3232

33-
def resetAllAttrs[T <: Tree](tree: T): T =
33+
def resetAllAttrs(tree: Tree): Tree =
3434
self.resetAllAttrs(tree)
3535

36-
def resetLocalAttrs[T <: Tree](tree: T): T =
36+
def resetLocalAttrs(tree: Tree): Tree =
3737
self.resetLocalAttrs(tree)
3838

3939
def runExpr(tree0: Tree, freeTypes: Map[FreeType, Type] = Map[FreeType, Type]()): Any = {

src/compiler/scala/tools/nsc/ast/Trees.scala

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,9 @@ trait Trees extends reflect.internal.Trees { self: Global =>
264264
// def resetAllAttrs[A<:Tree](x:A): A = { new ResetAttrsTraverser().traverse(x); x }
265265
// def resetLocalAttrs[A<:Tree](x:A): A = { new ResetLocalAttrsTraverser().traverse(x); x }
266266

267-
def resetAllAttrs[A <: Tree](x: A, leaveAlone: Tree => Boolean = null): A = new ResetAttrs(false, leaveAlone).transform(x)
268-
def resetLocalAttrs[A <: Tree](x: A, leaveAlone: Tree => Boolean = null): A = new ResetAttrs(true, leaveAlone).transform(x)
269-
def resetLocalAttrsKeepLabels[A<:Tree](x: A, leaveAlone: Tree => Boolean = null): A = new ResetAttrs(true, leaveAlone, true).transform(x)
267+
def resetAllAttrs(x: Tree, leaveAlone: Tree => Boolean = null): Tree = new ResetAttrs(false, leaveAlone).transform(x)
268+
def resetLocalAttrs(x: Tree, leaveAlone: Tree => Boolean = null): Tree = new ResetAttrs(true, leaveAlone).transform(x)
269+
def resetLocalAttrsKeepLabels(x: Tree, leaveAlone: Tree => Boolean = null): Tree = new ResetAttrs(true, leaveAlone, true).transform(x)
270270

271271
/** A transformer which resets symbol and tpe fields of all nodes in a given tree,
272272
* with special treatment of:
@@ -351,7 +351,7 @@ trait Trees extends reflect.internal.Trees { self: Global =>
351351
}
352352
}
353353

354-
def transform[T <: Tree](x: T): T = {
354+
def transform(x: Tree): Tree = {
355355
if (localOnly)
356356
new MarkLocals().traverse(x)
357357

@@ -361,10 +361,7 @@ trait Trees extends reflect.internal.Trees { self: Global =>
361361
trace("locals (%d total): %n".format(orderedLocals.size))(msg)
362362
}
363363

364-
val x1 = new Transformer().transform(x)
365-
// The loose invariant is a temporary workaround for SI-5803
366-
assert(x.getClass.isInstance(x1) || (x.isInstanceOf[ApplyConstructor] && x1.isInstanceOf[Apply]), (x.getClass, x1.getClass))
367-
x1.asInstanceOf[T]
364+
new Transformer().transform(x)
368365
}
369366
}
370367

src/library/scala/reflect/api/ToolBoxes.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,14 @@ trait ToolBoxes { self: Universe =>
5959
* Note that this does not revert the tree to its pre-typer shape.
6060
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
6161
*/
62-
def resetAllAttrs[T <: Tree](tree: T): T
62+
def resetAllAttrs(tree: Tree): Tree
6363

6464
/** Recursively resets locally defined symbols and types in a given tree.
6565
*
6666
* Note that this does not revert the tree to its pre-typer shape.
6767
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
6868
*/
69-
def resetLocalAttrs[T <: Tree](tree: T): T
69+
def resetLocalAttrs(tree: Tree): Tree
7070

7171
/** Compiles and runs a tree using this ToolBox.
7272
*

src/library/scala/reflect/makro/Typers.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,14 +66,14 @@ trait Typers {
6666
* Note that this does not revert the tree to its pre-typer shape.
6767
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
6868
*/
69-
def resetAllAttrs[T <: Tree](tree: T): T
69+
def resetAllAttrs(tree: Tree): Tree
7070

7171
/** Recursively resets locally defined symbols and types in a given tree.
7272
*
7373
* Note that this does not revert the tree to its pre-typer shape.
7474
* For more info, read up https://issues.scala-lang.org/browse/SI-5464.
7575
*/
76-
def resetLocalAttrs[T <: Tree](tree: T): T
76+
def resetLocalAttrs(tree: Tree): Tree
7777

7878
/** Represents an error during typechecking
7979
*/

0 commit comments

Comments
 (0)