diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-07-26 11:34:47 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-26 11:34:47 -0700 |
commit | efb74b73aa7ec157eb83c6cbf1fe341842357b2e (patch) | |
tree | 992dc1cb9f2f37fce1febcee8f58643389afa87f | |
parent | 4f749ceedb8b9a0a4417e2d2259c9a20853ad772 (diff) | |
parent | a2cba53e18864a5b9092f1e329c6e0afb09566c5 (diff) | |
download | scala-efb74b73aa7ec157eb83c6cbf1fe341842357b2e.tar.gz scala-efb74b73aa7ec157eb83c6cbf1fe341842357b2e.tar.bz2 scala-efb74b73aa7ec157eb83c6cbf1fe341842357b2e.zip |
Merge pull request #5301 from retronym/ticket/SD-167
SD-167 Fine tuning constructor pattern translation
Fixes scala/scala-dev#167
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Namers.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala | 3 | ||||
-rw-r--r-- | test/files/run/sd167.check | 1 | ||||
-rw-r--r-- | test/files/run/sd167.scala | 8 |
4 files changed, 12 insertions, 2 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index ad9377f8b4..caad4a907b 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1764,7 +1764,7 @@ trait Namers extends MethodSynthesis { * bugs waiting to be reported? If not, why not? When exactly do we need to * call this method? */ - def companionSymbolOf(original: Symbol, ctx: Context): Symbol = { + def companionSymbolOf(original: Symbol, ctx: Context): Symbol = if (original == NoSymbol) NoSymbol else { val owner = original.owner // SI-7264 Force the info of owners from previous compilation runs. // Doing this generally would trigger cycles; that's what we also diff --git a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala index f90e61ff92..1df3449ce6 100644 --- a/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/PatternTypers.scala @@ -79,6 +79,7 @@ trait PatternTypers { // do not update the symbol if the tree's symbol's type does not define an unapply member // (e.g. since it's some method that returns an object with an unapply member) val fun = inPlaceAdHocOverloadingResolution(fun0)(hasUnapplyMember) + val canElide = treeInfo.isQualifierSafeToElide(fun) val caseClass = companionSymbolOf(fun.tpe.typeSymbol.sourceModule, context) val member = unapplyMember(fun.tpe) def resultType = (fun.tpe memberType member).finalResultType @@ -94,7 +95,7 @@ trait PatternTypers { // Dueling test cases: pos/overloaded-unapply.scala, run/case-class-23.scala, pos/t5022.scala // A case class with 23+ params has no unapply method. // A case class constructor may be overloaded with unapply methods in the companion. - if (caseClass.isCase && !member.isOverloaded) + if (canElide && caseClass.isCase && !member.isOverloaded) logResult(s"convertToCaseConstructor($fun, $caseClass, pt=$pt)")(convertToCaseConstructor(fun, caseClass, pt)) else if (!reallyExists(member)) CaseClassConstructorError(fun, s"${fun.symbol} is not a case class, nor does it have an unapply/unapplySeq member") diff --git a/test/files/run/sd167.check b/test/files/run/sd167.check new file mode 100644 index 0000000000..587be6b4c3 --- /dev/null +++ b/test/files/run/sd167.check @@ -0,0 +1 @@ +x diff --git a/test/files/run/sd167.scala b/test/files/run/sd167.scala new file mode 100644 index 0000000000..5095e772ad --- /dev/null +++ b/test/files/run/sd167.scala @@ -0,0 +1,8 @@ +object Test { + implicit class ToExtractor(val s: StringContext) { + def x = {println("x"); Some } + } + def main(args: Array[String]) { + Some(1) match { case x"${a}" => } // used to convert to `case Some(a) =>` and omit side effects + } +} |