Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10166 from lrytz/t12641
Allow eta-expansion of methods with dependent types
- Loading branch information
Showing
8 changed files
with
125 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 0 additions & 4 deletions
4
test/files/neg/error_dependentMethodTpeConversionToFunction.check
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
test/files/neg/error_dependentMethodTpeConversionToFunction.scala
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
scala> object defs { | ||
val a = "obj" | ||
def aa: a.type = a | ||
def s = this | ||
def f(x: Int): a.type = a | ||
def g(x: Int)(y: x.type) = 0 | ||
def h(x: a.type)(y: a.type) = 0 | ||
} | ||
object defs | ||
|
||
scala> import defs._ | ||
import defs._ | ||
|
||
scala> val f1 = f _ | ||
val f1: Int => defs.a.type = <function> | ||
|
||
scala> val f2: Int => a.type = f | ||
val f2: Int => defs.a.type = <function> | ||
|
||
scala> val f3: Int => Object = f | ||
val f3: Int => Object = <function> | ||
|
||
scala> val g1 = g(10) _ | ||
val g1: Int(10) => Int = <function> | ||
|
||
scala> val g2: 10 => Int = g1 | ||
val g2: 10 => Int = <function> | ||
|
||
scala> val g3: 11 => Int = g(11) | ||
val g3: 11 => Int = <function> | ||
|
||
scala> val g4: Int => Int = g(11) // mismatch | ||
^ | ||
error: type mismatch; | ||
found : Int(11) => Int | ||
required: Int => Int | ||
|
||
scala> val h1 = s.h(aa) _ | ||
val h1: defs.a.type => Int = <function> | ||
|
||
scala> val h2: a.type => Int = h1 | ||
val h2: defs.a.type => Int = <function> | ||
|
||
scala> val h3: a.type => Int = s.h(aa) | ||
val h3: defs.a.type => Int = <function> | ||
|
||
scala> :quit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
object NoMoreNeg { | ||
def foo(x: AnyRef): x.type = x | ||
val x: AnyRef => Any = foo | ||
} | ||
|
||
object t12641 { | ||
def f(sb: StringBuilder) = Option("").foreach(sb.append) | ||
} | ||
|
||
object t12641a { | ||
trait A { | ||
def foo(s: String): this.type | ||
def foo(s: Int): this.type | ||
} | ||
trait T { | ||
val a1: A | ||
val o: Option[String] | ||
|
||
def t(a2: A): Unit = { | ||
o.foreach(a1.foo) | ||
o.foreach(a2.foo) | ||
|
||
val f2: String => a2.type = a2.foo | ||
val f3: String => A = a2.foo | ||
} | ||
} | ||
} | ||
|
||
object t12641b { | ||
trait A { | ||
def foo(s: String): this.type | ||
} | ||
trait T { | ||
val a1: A | ||
val o: Option[String] | ||
|
||
def t(a2: A): Unit = { | ||
o.foreach(a1.foo) | ||
o.foreach(a2.foo) | ||
|
||
val f1 = a2.foo _ | ||
val f2: String => a2.type = a2.foo | ||
val f3: String => A = a2.foo | ||
} | ||
} | ||
} | ||
|
||
import scala.tools.partest._ | ||
|
||
object Test extends ReplTest with Lambdaless { | ||
def code = """ | ||
object defs { | ||
val a = "obj" | ||
def aa: a.type = a | ||
def s = this | ||
def f(x: Int): a.type = a | ||
def g(x: Int)(y: x.type) = 0 | ||
def h(x: a.type)(y: a.type) = 0 | ||
} | ||
import defs._ | ||
val f1 = f _ | ||
val f2: Int => a.type = f | ||
val f3: Int => Object = f | ||
val g1 = g(10) _ | ||
val g2: 10 => Int = g1 | ||
val g3: 11 => Int = g(11) | ||
val g4: Int => Int = g(11) // mismatch | ||
val h1 = s.h(aa) _ | ||
val h2: a.type => Int = h1 | ||
val h3: a.type => Int = s.h(aa) | ||
""".trim | ||
} |