diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2016-07-14 11:50:22 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2016-07-14 12:04:21 +1000 |
commit | f806073d32a476d156f1b3ec24c17f35ed65b4c3 (patch) | |
tree | 2a1389a194bdcc7153eae8c0bb0dd1951721b3e4 /test/files/specialized/arrays-traits.scala | |
parent | 4e564efb04e508ccc0f479cf1a25331501927d88 (diff) | |
download | scala-f806073d32a476d156f1b3ec24c17f35ed65b4c3.tar.gz scala-f806073d32a476d156f1b3ec24c17f35ed65b4c3.tar.bz2 scala-f806073d32a476d156f1b3ec24c17f35ed65b4c3.zip |
SD-183 Make refinement classes ineligible as SAMs
Only non-refinement class types need apply, which is the same
restriction that we levy on parent types of a class.
```
scala> class C; class D extends C; type CD = C with D; class E extends CD
<console>:11: error: class type required but C with D found
class C; class D extends C; type CD = C with D; class E extends CD
^
scala> class C; class D extends C; type DC = D with C; class E extends DC
<console>:11: error: class type required but D with C found
class C; class D extends C; type DC = D with C; class E extends DC
^
```
Prior to this change:
```
scala> trait T { def t(a: Any): Any }; trait U; abstract class C extends T
defined trait T
defined trait U
defined class C
````
For indy-based lambdas:
```
scala> val tu: T with U = x => x
tu: T with U = $$Lambda$1812/317644782@3c3c4a71
scala> tu: U
java.lang.ClassCastException: $$Lambda$1812/317644782 cannot be cast to U
... 30 elided
```
For anon class based lambdas:
```
scala> ((x => x): C with U)
<console>:14: error: class type required but C with U found
((x => x): C with U)
^
scala> implicit def anyToCWithU(a: Any): C with U = new C with U { def t(a: Any) = a }
warning: there was one feature warning; re-run with -feature for details
anyToCWithU: (a: Any)C with U
scala> (((x: Any) => x): C with U) // SAM chosen but fails to typecheck the expansion uncurry
<console>:17: error: class type required but C with U found
(((x: Any) => x): C with U) // SAM chosen but fails to typecheck the expansion uncurry
^
```
Fixes https://github.com/scala/scala-dev/issues/183
While it is tempting to special case refinement classes with no decls by
flattening their parents into the parents of the lambda. But there are
some subtle issues at play with lineriazation order, as Martin pointed out
when I brought this up before: http://www.scala-lang.org/old/node/6817.html
Diffstat (limited to 'test/files/specialized/arrays-traits.scala')
0 files changed, 0 insertions, 0 deletions