summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-04-24 18:40:12 +0200
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-04-24 18:54:21 +0200
commita47acbc36d312cc12ab02f4564edff1deb93d941 (patch)
treec433d551cb69e7d26f7f291e4659a45c4f569c08
parent2890714d7bcdd55b7a62091dcdf031cc3efe0822 (diff)
downloadscala-a47acbc36d312cc12ab02f4564edff1deb93d941.tar.gz
scala-a47acbc36d312cc12ab02f4564edff1deb93d941.tar.bz2
scala-a47acbc36d312cc12ab02f4564edff1deb93d941.zip
copy BackQuotedIdent trees (don't copy as Ident)
typer synthesized the wrong isDefinedAt method in typedMatchAnon because a BackQuotedIdent was copied as an Ident, so that the equality check was performed in applyOrElse (since it operates on the original tree), but not in isDefinedAt (since it operates on the copy, which collapsed Ident and BackQuotedIdent)
-rw-r--r--src/compiler/scala/reflect/internal/TreePrinters.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala3
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala2
-rw-r--r--src/library/scala/reflect/api/Trees.scala5
-rw-r--r--test/files/run/virtpatmat_partial_backquoted.check1
-rw-r--r--test/files/run/virtpatmat_partial_backquoted.scala12
6 files changed, 24 insertions, 2 deletions
diff --git a/src/compiler/scala/reflect/internal/TreePrinters.scala b/src/compiler/scala/reflect/internal/TreePrinters.scala
index 486a3d3567..3093bb049a 100644
--- a/src/compiler/scala/reflect/internal/TreePrinters.scala
+++ b/src/compiler/scala/reflect/internal/TreePrinters.scala
@@ -373,6 +373,9 @@ trait TreePrinters extends api.TreePrinters { self: SymbolTable =>
case Select(qualifier, name) =>
print(backquotedPath(qualifier), ".", symName(tree, name))
+ case bqid: BackQuotedIdent =>
+ print("`%s`" format symName(tree, bqid.name))
+
case Ident(name) =>
print(symName(tree, name))
diff --git a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala
index 3be8397a9c..96d92e0609 100644
--- a/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/PatMatVirtualiser.scala
@@ -136,7 +136,7 @@ trait PatMatVirtualiser extends ast.TreeDSL { self: Analyzer =>
// (that would require more sophistication when generating trees,
// and the only place that emits Matches after typers is for exception handling anyway)
if(phase.id >= currentRun.uncurryPhase.id) debugwarn("running translateMatch at "+ phase +" on "+ scrut +" match "+ cases)
-
+ // println("translating "+ cases.mkString("{", "\n", "}"))
val scrutSym = freshSym(scrut.pos, pureType(scrutType)) setFlag SYNTH_CASE
// pt = Any* occurs when compiling test/files/pos/annotDepMethType.scala with -Xexperimental
combineCases(scrut, scrutSym, cases map translateCase(scrutSym, pt), pt, matchOwner, matchFailGenOverride)
@@ -987,6 +987,7 @@ class Foo(x: Other) { x._1 } // no error in this order
fixerUpper(owner, scrut.pos){
val ptDefined = if (isFullyDefined(pt)) pt else NoType
def matchFailGen = (matchFailGenOverride orElse Some(CODE.MATCHERROR(_: Tree)))
+ // println("combining cases: "+ (casesNoSubstOnly.map(_.mkString(" >> ")).mkString("{", "\n", "}")))
emitSwitch(scrut, scrutSym, casesNoSubstOnly, pt, matchFailGenOverride).getOrElse{
if (casesNoSubstOnly nonEmpty) {
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index ba6a363095..1414424a0b 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -2288,6 +2288,7 @@ trait Typers extends Modes with Adaptations with Taggings with PatMatVirtualiser
// need to duplicate the cases before typing them to generate the apply method, or the symbols will be all messed up
val casesTrue = if (isPartial) cases map (c => deriveCaseDef(c)(x => TRUE_typed).duplicate) else Nil
+ // println("casesTrue "+ casesTrue)
def parentsPartial(targs: List[Type]) = List(appliedType(AbstractPartialFunctionClass.typeConstructor, targs), SerializableClass.tpe)
def applyMethod = {
@@ -2373,6 +2374,7 @@ trait Typers extends Modes with Adaptations with Taggings with PatMatVirtualiser
}
val members = if (isPartial) {
+ // TODO: don't check for MarkerCPSTypes -- check whether all targs are subtype of any (which they are not under CPS)
if ((MarkerCPSTypes ne NoSymbol) && (targs exists (_ hasAnnotation MarkerCPSTypes))) List(applyMethod, isDefinedAtMethod)
else List(applyOrElseMethodDef, isDefinedAtMethod)
} else List(applyMethod)
diff --git a/src/library/scala/reflect/api/Trees.scala b/src/library/scala/reflect/api/Trees.scala
index 6e2e8261e7..2f6dc820a5 100644
--- a/src/library/scala/reflect/api/Trees.scala
+++ b/src/library/scala/reflect/api/Trees.scala
@@ -1171,7 +1171,10 @@ trait Trees { self: Universe =>
def Select(tree: Tree, qualifier: Tree, selector: Name) =
new Select(qualifier, selector).copyAttrs(tree)
def Ident(tree: Tree, name: Name) =
- new Ident(name).copyAttrs(tree)
+ (tree match {
+ case _ : BackQuotedIdent => new BackQuotedIdent(name)
+ case _ => new Ident(name)
+ }).copyAttrs(tree)
def ReferenceToBoxed(tree: Tree, idt: Ident) =
new ReferenceToBoxed(idt).copyAttrs(tree)
def Literal(tree: Tree, value: Constant) =
diff --git a/test/files/run/virtpatmat_partial_backquoted.check b/test/files/run/virtpatmat_partial_backquoted.check
new file mode 100644
index 0000000000..8ab8f29677
--- /dev/null
+++ b/test/files/run/virtpatmat_partial_backquoted.check
@@ -0,0 +1 @@
+Set(You got me!)
diff --git a/test/files/run/virtpatmat_partial_backquoted.scala b/test/files/run/virtpatmat_partial_backquoted.scala
new file mode 100644
index 0000000000..6d92229d6b
--- /dev/null
+++ b/test/files/run/virtpatmat_partial_backquoted.scala
@@ -0,0 +1,12 @@
+object Test extends App {
+ class Region { override def toString = "You got me!" }
+ class SymbolType
+ case class SymbolInfo(tp: SymbolType, regions: List[Region], x: Any)
+
+ def findRegionsWithSymbolType(rawSymbolInfos: Seq[SymbolInfo], symbolType: SymbolType): Set[Region] =
+ rawSymbolInfos.collect { case SymbolInfo(`symbolType`, regions, _) => regions }.flatten.toSet
+
+ val stp = new SymbolType
+ val stp2 = new SymbolType
+ println(findRegionsWithSymbolType(List(SymbolInfo(stp2, List(), null), SymbolInfo(stp, List(new Region), null)), stp))
+} \ No newline at end of file