New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow eta-expansion of methods with dependent types #10166
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand the restriction yet, but
etaExpand
still has adriaanm comment that not supported.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I'll be off for a week 🇷🇴 and don't have more time right now to try to break it, will get back to it after.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Enjoy! Insert joke about children as dependent types.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a few more tests, AFAICT
etaExpand
works well with dependent method types