Skip to content

Commit

Permalink
fixes a problem with an extractor object overloaded by a regular def
Browse files Browse the repository at this point in the history
  • Loading branch information
xeno-by committed May 11, 2012
1 parent 2422b06 commit 82f3e49
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/compiler/scala/reflect/internal/Types.scala
Expand Up @@ -2663,6 +2663,10 @@ trait Types extends api.Types { self: SymbolTable =>
override def kind = "OverloadedType"
}

def overloadedType(pre: Type, alternatives: List[Symbol]): Type =
if (alternatives.tail.isEmpty) pre memberType alternatives.head
else OverloadedType(pre, alternatives)

/** A class remembering a type instantiation for some a set of overloaded
* polymorphic symbols.
* Not used after phase `typer`.
Expand Down
7 changes: 6 additions & 1 deletion src/compiler/scala/tools/nsc/typechecker/Typers.scala
Expand Up @@ -958,9 +958,14 @@ trait Typers extends Modes with Adaptations with Taggings {
* see test/files/../t5189*.scala
*/
def adaptConstrPattern(): Tree = { // (5)
val extractor = tree.symbol.filter(sym => reallyExists(unapplyMember(sym.tpe)))
def isExtractor(sym: Symbol) = reallyExists(unapplyMember(sym.tpe))
val extractor = tree.symbol filter isExtractor
if (extractor != NoSymbol) {
tree setSymbol extractor
tree.tpe match {
case OverloadedType(pre, alts) => tree.tpe = overloadedType(pre, alts filter isExtractor)
case _ =>
}
val unapply = unapplyMember(extractor.tpe)
val clazz = unapplyParameterType(unapply)

Expand Down
32 changes: 32 additions & 0 deletions test/files/pos/overloaded_extractor_and_regular_def.scala
@@ -0,0 +1,32 @@
trait TreesBase {
type Tree

type Apply <: Tree

val Apply: ApplyExtractor

abstract class ApplyExtractor {
def apply(x: Int): Apply
def unapply(apply: Apply): Option[Int]
}
}

trait TreesApi extends TreesBase {
def Apply(x: String)
}

class Universe extends TreesApi {
abstract class Tree
case class Apply(x: Int) extends Tree
object Apply extends ApplyExtractor
def Apply(x: String) = Apply(x.toInt)
}

object Test extends App {
def foo(tapi: TreesApi) {
import tapi._
def bar(tree: Tree) {
val Apply(x) = tree
}
}
}

0 comments on commit 82f3e49

Please sign in to comment.