summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan@lightbend.com>2016-07-26 11:31:06 -0700
committerGitHub <noreply@github.com>2016-07-26 11:31:06 -0700
commit4f749ceedb8b9a0a4417e2d2259c9a20853ad772 (patch)
tree8e1d0da9b08a7a49157e5ebe468e14e177fc1516
parent2f95a247d69843547901501c5bca976d0b95ac0a (diff)
parentf806073d32a476d156f1b3ec24c17f35ed65b4c3 (diff)
downloadscala-4f749ceedb8b9a0a4417e2d2259c9a20853ad772.tar.gz
scala-4f749ceedb8b9a0a4417e2d2259c9a20853ad772.tar.bz2
scala-4f749ceedb8b9a0a4417e2d2259c9a20853ad772.zip
Merge pull request #5279 from retronym/ticket/SD-183
SD-183 Make refinement classes ineligible as SAMs
-rw-r--r--src/reflect/scala/reflect/internal/Definitions.scala4
-rw-r--r--test/files/neg/sammy_restrictions.check33
-rw-r--r--test/files/neg/sammy_restrictions.scala7
3 files changed, 30 insertions, 14 deletions
diff --git a/src/reflect/scala/reflect/internal/Definitions.scala b/src/reflect/scala/reflect/internal/Definitions.scala
index fe6d88e7c7..0342daf113 100644
--- a/src/reflect/scala/reflect/internal/Definitions.scala
+++ b/src/reflect/scala/reflect/internal/Definitions.scala
@@ -837,9 +837,9 @@ trait Definitions extends api.StandardDefinitions {
* The class defining the method is a supertype of `tp` that
* has a public no-arg primary constructor.
*/
- def samOf(tp: Type): Symbol = if (!doSam) NoSymbol else {
+ def samOf(tp: Type): Symbol = if (!doSam) NoSymbol else if (!isNonRefinementClassType(unwrapToClass(tp))) NoSymbol else {
// look at erased type because we (only) care about what ends up in bytecode
- // (e.g., an alias type or intersection type is fine as long as the intersection dominator compiles to an interface)
+ // (e.g., an alias type is fine as long as is compiles to a single-abstract-method)
val tpSym: Symbol = erasure.javaErasure(tp).typeSymbol
if (tpSym.exists && tpSym.isClass
diff --git a/test/files/neg/sammy_restrictions.check b/test/files/neg/sammy_restrictions.check
index 09579cbe21..0225c61ac1 100644
--- a/test/files/neg/sammy_restrictions.check
+++ b/test/files/neg/sammy_restrictions.check
@@ -1,51 +1,62 @@
-sammy_restrictions.scala:35: error: type mismatch;
+sammy_restrictions.scala:38: error: type mismatch;
found : () => Int
required: NoAbstract
(() => 0) : NoAbstract
^
-sammy_restrictions.scala:36: error: type mismatch;
+sammy_restrictions.scala:39: error: type mismatch;
found : Int => Int
required: TwoAbstract
((x: Int) => 0): TwoAbstract
^
-sammy_restrictions.scala:37: error: type mismatch;
+sammy_restrictions.scala:40: error: type mismatch;
found : Int => Int
required: NoEmptyConstructor
((x: Int) => 0): NoEmptyConstructor
^
-sammy_restrictions.scala:38: error: type mismatch;
+sammy_restrictions.scala:41: error: type mismatch;
found : Int => Int
required: MultipleConstructorLists
((x: Int) => 0): MultipleConstructorLists
^
-sammy_restrictions.scala:39: error: type mismatch;
+sammy_restrictions.scala:42: error: type mismatch;
found : Int => Int
required: OneEmptySecondaryConstructor
((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
^
-sammy_restrictions.scala:40: error: type mismatch;
+sammy_restrictions.scala:43: error: type mismatch;
found : Int => Int
required: MultipleMethodLists
((x: Int) => 0): MultipleMethodLists
^
-sammy_restrictions.scala:41: error: type mismatch;
+sammy_restrictions.scala:44: error: type mismatch;
found : Int => Int
required: ImplicitConstructorParam
((x: Int) => 0): ImplicitConstructorParam
^
-sammy_restrictions.scala:42: error: type mismatch;
+sammy_restrictions.scala:45: error: type mismatch;
found : Int => Int
required: ImplicitMethodParam
((x: Int) => 0): ImplicitMethodParam
^
-sammy_restrictions.scala:43: error: type mismatch;
+sammy_restrictions.scala:46: error: type mismatch;
found : Int => Int
required: PolyMethod
((x: Int) => 0): PolyMethod
^
-sammy_restrictions.scala:44: error: type mismatch;
+sammy_restrictions.scala:47: error: type mismatch;
found : Int => Int
required: SelfTp
((x: Int) => 0): SelfTp
^
-10 errors found
+sammy_restrictions.scala:48: error: type mismatch;
+ found : Int => Int
+ required: T1 with U1
+ ((x: Int) => 0): T1 with U1
+ ^
+sammy_restrictions.scala:49: error: type mismatch;
+ found : Int => Int
+ required: Test.NonClassTypeRefinement
+ (which expands to) DerivedOneAbstract with OneAbstract
+ ((x: Int) => 0): NonClassTypeRefinement
+ ^
+12 errors found
diff --git a/test/files/neg/sammy_restrictions.scala b/test/files/neg/sammy_restrictions.scala
index ff2c16b679..dee4f1f247 100644
--- a/test/files/neg/sammy_restrictions.scala
+++ b/test/files/neg/sammy_restrictions.scala
@@ -27,9 +27,12 @@ abstract class DerivedOneAbstract extends OneAbstract
abstract class SelfTp { self: NoAbstract => def ap(a: Int): Any }
abstract class SelfVar { self => def ap(a: Int): Any }
+trait T1 { def t(a: Int): Int }; trait U1
+
object Test {
implicit val s: String = ""
- type NonClassType = DerivedOneAbstract with OneAbstract
+ type NonClassTypeRefinement = DerivedOneAbstract with OneAbstract
+ type NonClassType = DerivedOneAbstract
// errors:
(() => 0) : NoAbstract
@@ -42,6 +45,8 @@ object Test {
((x: Int) => 0): ImplicitMethodParam
((x: Int) => 0): PolyMethod
((x: Int) => 0): SelfTp
+ ((x: Int) => 0): T1 with U1
+ ((x: Int) => 0): NonClassTypeRefinement
// allowed:
((x: Int) => 0): OneEmptyConstructor