New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Crash when moving a macro argument to a local class #6711
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6711?orig=1 |
@Atry said: |
@xeno-by said: |
@retronym said: private val internalSyms = origTree.collect {
case dt: DefTree => dt.symbol
}
private def resetInternalAttrs(tree: Tree) = utils.resetInternalAttrs(tree, internalSyms) def resetInternalAttrs(tree: Tree, internalSyms: List[Symbol]) =
new ResetInternalAttrs(internalSyms.toSet).transform(tree)
/**
* Adaptation of [[scala.reflect.internal.Trees.ResetAttrs]]
*
* A transformer which resets symbol and tpe fields of all nodes in a given tree,
* with special treatment of:
* `TypeTree` nodes: are replaced by their original if it exists, otherwise tpe field is reset
* to empty if it started out empty or refers to local symbols (which are erased).
* `TypeApply` nodes: are deleted if type arguments end up reverted to empty
*
* `This` and `Ident` nodes referring to an external symbol are ''not'' reset.
*/
private final class ResetInternalAttrs(internalSyms: Set[Symbol]) extends Transformer {
import language.existentials
override def transform(tree: Tree): Tree = super.transform {
def isExternal = tree.symbol != NoSymbol && !internalSyms(tree.symbol)
tree match {
case tpt: TypeTree => resetTypeTree(tpt)
case TypeApply(fn, args)
if args map transform exists (_.isEmpty) => transform(fn)
case EmptyTree => tree
case (_: Ident | _: This) if isExternal => tree // #35 Don't reset the symbol of Ident/This bound outside of the async block
case _ => resetTree(tree)
}
}
private def resetTypeTree(tpt: TypeTree): Tree = {
if (tpt.original != null)
transform(tpt.original)
else if (tpt.tpe != null && tpt.asInstanceOf[symtab.TypeTree forSome {val symtab: reflect.internal.SymbolTable}].wasEmpty) {
val dupl = tpt.duplicate
dupl.tpe = null
dupl
}
else tpt
}
private def resetTree(tree: Tree): Tree = {
val hasSymbol: Boolean = {
val reflectInternalTree = tree.asInstanceOf[symtab.Tree forSome {val symtab: reflect.internal.SymbolTable}]
reflectInternalTree.hasSymbol
}
val dupl = tree.duplicate
if (hasSymbol)
dupl.symbol = NoSymbol
dupl.tpe = null
dupl
}
} |
@xeno-by said: |
@retronym said: object Foo {
def blammo = 0
def foo {
macroCall {
this.blammo
}
// rewrites to:
// object o {
// def apply { this.blammo }
// }.apply
}
} |
@xeno-by said: |
stale, unclear if actionable |
The text was updated successfully, but these errors were encountered: