Skip to content

Fix ambiguous unapply for TASTy reflect Parent #4998

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

Merged
merged 1 commit into from
Aug 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions compiler/src/dotty/tools/dotc/tastyreflect/TreeOpsImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import dotty.tools.dotc.core
import dotty.tools.dotc.core.Decorators._
import dotty.tools.dotc.core.StdNames.nme
import dotty.tools.dotc.core._
import dotty.tools.dotc.reporting.Reporter
import dotty.tools.dotc.reporting.diagnostic.MessageContainer
import dotty.tools.dotc.tastyreflect.FromSymbol.{definitionFromSym, packageDefFromSym}

trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with Helpers {
Expand Down Expand Up @@ -399,4 +397,5 @@ trait TreeOpsImpl extends scala.tasty.reflect.TreeOps with TastyCoreImpl with He
}
}

def termAsParent(term: Term): Parent = term
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems dangerous to me, as any term can now be disguised as Parent. The same for TypeTree. Conceptually, how it is different from making Parent a supertype of Term and TypeTree?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not conceptually different, but it solves the ambiguity in the extractor when passing a Term as term could be a Tree or a Parent. This will be removed when we bootstrap and I'll be able to define type Parent = Term | TypeTree and have a simple extractor for both.

}
Original file line number Diff line number Diff line change
Expand Up @@ -153,4 +153,5 @@ trait TypeOrBoundsTreesOpsImpl extends scala.tasty.reflect.TypeOrBoundsTreeOps w
}
}

def typeTreeAsParent(typeTree: TypeTree): Parent = typeTree
}
53 changes: 28 additions & 25 deletions library/src/scala/tasty/reflect/TastyCore.scala
Original file line number Diff line number Diff line change
Expand Up @@ -13,29 +13,29 @@ package scala.tasty.reflect
* | +- PackageDef
* |
* +- Term --------+- Ident
* / +- Select
* / +- Literal
* / +- This
* / +- New
* / +- NamedArg
* / +- Apply
* / +- TypeApply
* / +- Super
* / +- Typed
* / +- Assign
* / +- Block
* +- Parent ----+ +- Lambda
* \ +- If
* \ +- Match
* \ +- Try
* \ +- Return
* \ +- Repeated
* \ +- Inlined
* \ +- SelectOuter
* \ +- While
* \ +- DoWhile
* \
* \
* +- Select
* +- Literal
* +- This
* +- New
* +- NamedArg
* +- Apply
* +- TypeApply
* +- Super
* +- Typed
* +- Assign
* +- Block
* +- Lambda
* +- If
* +- Match
* +- Try
* +- Return
* +- Repeated
* +- Inlined
* +- SelectOuter
* +- While
* +- DoWhile
*
*
* +- TypeTree ----+- Synthetic
* | +- TypeIdent
* | +- TermSelect
Expand Down Expand Up @@ -98,6 +98,9 @@ package scala.tasty.reflect
*
* +- Symbol
*
* Aliases:
* # Parent = Term | TypeTree
*
* ```
*/
trait TastyCore {
Expand All @@ -120,7 +123,7 @@ trait TastyCore {
type DefDef <: Definition
type ValDef <: Definition
type PackageDef <: Definition
type Term <: Statement with Parent // TODO: When bootstrapped, remove `Parent`
type Term <: Statement

/** Branch of a pattern match or catch clause */
type CaseDef
Expand All @@ -130,7 +133,7 @@ trait TastyCore {

/** Tree representing a type written in the source */
type TypeOrBoundsTree
type TypeTree <: TypeOrBoundsTree with Parent // TODO: When bootstrapped, remove `Parent`
type TypeTree <: TypeOrBoundsTree
type TypeBoundsTree <: TypeOrBoundsTree

type TypeOrBounds
Expand Down
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/TreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -306,4 +306,5 @@ trait TreeOps extends TastyCore {
}
}

implicit def termAsParent(term: Term): Parent
}
1 change: 1 addition & 0 deletions library/src/scala/tasty/reflect/TypeOrBoundsTreeOps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,4 +119,5 @@ trait TypeOrBoundsTreeOps extends TastyCore {
def unapply(typeOrBoundsTree: TypeOrBoundsTree)(implicit ctx: Context): Boolean
}

implicit def typeTreeAsParent(term: TypeTree): Parent
}
33 changes: 33 additions & 0 deletions tests/pos-special/fatal-warnings/tasty-parent-unapply.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import scala.quoted._

import scala.tasty.Tasty

object Macros {


def impl(tasty: Tasty): Unit = {
import tasty._

def foo(tree: Tree, term: Term, typeTree: TypeTree, parent: Parent) = {

tree match {
case IsTerm(tree) =>
}

term match {
case IsTerm(term) =>
}

typeTree match {
case IsTypeTree(typeTree) =>
}

parent match {
case IsTerm(typeTree) =>
case IsTypeTree(typeTree) =>
}

}
}

}