diff options
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 18 | ||||
-rw-r--r-- | test/files/pos/unapplyVal.scala | 18 |
2 files changed, 34 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 96238bd76e..e8a52e9b2f 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -1654,11 +1654,25 @@ trait Typers { self: Analyzer => arg.tpe = typer1.infer.inferTypedPattern(tree.pos, unappFormal, arg.tpe) //todo: replace arg with arg.asInstanceOf[inferTypedPattern(unappFormal, arg.tpe)] instead. } - // Console.println("unapply "+fun.tpe) + val funPrefix = fun.tpe.prefix match { + case tt @ ThisType(sym) => + //Console.println(" sym="+sym+" "+" .isPackageClass="+sym.isPackageClass+" .isModuleClass="+sym.isModuleClass); + //Console.println(" funsymown="+fun.symbol.owner+" .isClass+"+fun.symbol.owner.isClass); + //Console.println(" contains?"+sym.tpe.decls.lookup(fun.symbol.name)); + if(sym != fun.symbol.owner && sym.isPackageClass /*(1)*/ ) { // (1) see 'files/pos/unapplyVal.scala' + if(fun.symbol.owner.isClass) { + mkThisType(fun.symbol.owner) + } else { + NoPrefix // see 'files/run/unapplyComplex.scala' + } + } else tt + case st @ SingleType(pre, sym) => st + case xx => xx // cannot happen? + } val fun1untyped = atPos(fun.pos) { Apply( Select( - gen.mkAttributedRef(fun.tpe.prefix, fun.symbol) setType null, + gen.mkAttributedRef(funPrefix, fun.symbol) setType null, // setType null is necessary so that ref will be stabilized; see bug 881 unapp), List(arg)) diff --git a/test/files/pos/unapplyVal.scala b/test/files/pos/unapplyVal.scala new file mode 100644 index 0000000000..3816152f20 --- /dev/null +++ b/test/files/pos/unapplyVal.scala @@ -0,0 +1,18 @@ +package test // bug #1215 + +class Async { + def unapply(scrut: Any): Option[Any] = None +} + +class Buffer { + val Put = new Async + //case class Put(x: int) + + def joinPat(x: Any): Unit = { + x match { + case Put => + case Put(y) => + println("returning "+y) + } + } +} |