Skip to content

Commit 7fbaf94

Browse files
retronymadriaanm
authored andcommitted
Test cases for SAM restrictions.
Only one seems to indicate something new: ((x: Int) => 0): NonClassType I believe that we shouldn't pursue SAM translation for that case, and fallthrough to Function1. That would allow for an implicit view to finish the job.
1 parent 1571af7 commit 7fbaf94

File tree

3 files changed

+95
-0
lines changed

3 files changed

+95
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
sammy_restrictions.scala:31: error: type mismatch;
2+
found : () => Int
3+
required: NoAbstract
4+
(() => 0) : NoAbstract
5+
^
6+
sammy_restrictions.scala:32: error: type mismatch;
7+
found : Int => Int
8+
required: TwoAbstract
9+
((x: Int) => 0): TwoAbstract
10+
^
11+
sammy_restrictions.scala:34: error: class type required but DerivedOneAbstract with OneAbstract found
12+
((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here.
13+
^
14+
sammy_restrictions.scala:35: error: type mismatch;
15+
found : Int => Int
16+
required: NoEmptyConstructor
17+
((x: Int) => 0): NoEmptyConstructor
18+
^
19+
sammy_restrictions.scala:37: error: type mismatch;
20+
found : Int => Int
21+
required: OneEmptySecondaryConstructor
22+
((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
23+
^
24+
sammy_restrictions.scala:38: error: type mismatch;
25+
found : Int => Int
26+
required: MultipleConstructorLists
27+
((x: Int) => 0): MultipleConstructorLists
28+
^
29+
sammy_restrictions.scala:39: error: type mismatch;
30+
found : Int => Int
31+
required: MultipleMethodLists
32+
((x: Int) => 0): MultipleMethodLists
33+
^
34+
sammy_restrictions.scala:40: error: type mismatch;
35+
found : Int => Int
36+
required: ImplicitConstructorParam
37+
((x: Int) => 0): ImplicitConstructorParam
38+
^
39+
sammy_restrictions.scala:41: error: type mismatch;
40+
found : Int => Int
41+
required: ImplicitMethodParam
42+
((x: Int) => 0): ImplicitMethodParam
43+
^
44+
sammy_restrictions.scala:44: error: type mismatch;
45+
found : Int => Int
46+
required: PolyMethod
47+
((x: Int) => 0): PolyMethod
48+
^
49+
10 errors found
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-Xexperimental
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class NoAbstract
2+
3+
class TwoAbstract { def ap(a: Int): Int; def pa(a: Int): Int }
4+
5+
class Base // check that the super class constructor isn't considered.
6+
class NoEmptyConstructor(a: Int) extends Base { def this(a: String) = this(0); def ap(a: Int): Int }
7+
8+
class OneEmptyConstructor() { def this(a: Int) = this(); def ap(a: Int): Int }
9+
10+
class OneEmptySecondaryConstructor(a: Int) { def this() = this(0); def ap(a: Int): Int }
11+
12+
class MultipleConstructorLists()() { def ap(a: Int): Int }
13+
14+
class MultipleMethodLists()() { def ap(a: Int)(): Int }
15+
16+
class ImplicitConstructorParam()(implicit a: String) { def ap(a: Int): Int }
17+
18+
class ImplicitMethodParam() { def ap(a: Int)(implicit b: String): Int }
19+
20+
class PolyClass[T] { def ap(a: T): T }
21+
22+
class PolyMethod { def ap[T](a: T): T }
23+
24+
class OneAbstract { def ap(a: Any): Any }
25+
class DerivedOneAbstract extends OneAbstract
26+
27+
object Test {
28+
implicit val s: String = ""
29+
type NonClassType = DerivedOneAbstract with OneAbstract
30+
31+
(() => 0) : NoAbstract
32+
((x: Int) => 0): TwoAbstract
33+
((x: Int) => 0): DerivedOneAbstract // okay
34+
((x: Int) => 0): NonClassType // "class type required". I think we should avoid SAM translation here.
35+
((x: Int) => 0): NoEmptyConstructor
36+
((x: Int) => 0): OneEmptyConstructor // okay
37+
((x: Int) => 0): OneEmptySecondaryConstructor // derived class must have an empty *primary* to call.
38+
((x: Int) => 0): MultipleConstructorLists
39+
((x: Int) => 0): MultipleMethodLists
40+
((x: Int) => 0): ImplicitConstructorParam
41+
((x: Int) => 0): ImplicitMethodParam
42+
43+
((x: Int) => 0): PolyClass[Int] // okay
44+
((x: Int) => 0): PolyMethod
45+
}

0 commit comments

Comments
 (0)