diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2015-10-27 14:37:44 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2015-10-27 16:08:15 +1000 |
commit | 639e52ae7e128025f6eb57957a590b808d83a9a4 (patch) | |
tree | 19958923ec2beea7b770ccf2197fef6930e830f1 /src | |
parent | b194a4e7230334e441cd31b617fdce8e329dfa3a (diff) | |
download | scala-639e52ae7e128025f6eb57957a590b808d83a9a4.tar.gz scala-639e52ae7e128025f6eb57957a590b808d83a9a4.tar.bz2 scala-639e52ae7e128025f6eb57957a590b808d83a9a4.zip |
SI-9178 Don't eta expand param-less method types to SAMs
Otherwise, we can end up with a subtle source incompatibility with
the pre-SAM regime. Arguably we should phase out eta expansion to
Function0 as well, but I'll leave that for another day.
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/Typers.scala | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 45ebbd532d..d06a4a5d80 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -862,7 +862,14 @@ trait Typers extends Adaptations with Tags with TypersTracking with PatternTyper case Block(_, tree1) => tree1.symbol case _ => tree.symbol } - if (!meth.isConstructor && (isFunctionType(pt) || samOf(pt).exists)) { // (4.2) + def shouldEtaExpandToSam: Boolean = { + // SI-9536 don't adapt parameterless method types to a to SAM's, fall through to empty application + // instead for backwards compatiblity with 2.11. See comments of that ticket and SI-7187 + // for analogous trouble with non-SAM eta expansion. Suggestions there are: a) deprecate eta expansion to Function0, + // or b) switch the order of eta-expansion and empty application in this adaptation. + !mt.params.isEmpty && samOf(pt).exists + } + if (!meth.isConstructor && (isFunctionType(pt) || shouldEtaExpandToSam)) { // (4.2) debuglog(s"eta-expanding $tree: ${tree.tpe} to $pt") checkParamsConvertible(tree, tree.tpe) val tree0 = etaExpand(context.unit, tree, this) |