-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add constructors for Select #5796
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
Merged
liufengyun
merged 5 commits into
scala:master
from
dotty-staging:add-select-constructor
Feb 20, 2019
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
eeb1218
Add constructors for Select
liufengyun bf6a1b7
Set positions for constructed trees manually
liufengyun 7e433cf
Fix rebase errors
liufengyun 29d4ccb
Rebase to set default pos in constructors
liufengyun 3b9306b
Add documentation for Select constructors
liufengyun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
47 changes: 47 additions & 0 deletions
47
tests/run-with-compiler/reflect-select-constructor/assert_1.scala
This file contains hidden or 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,47 @@ | ||
import scala.quoted._ | ||
import scala.tasty._ | ||
|
||
object scalatest { | ||
|
||
inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), '("")) | ||
|
||
def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = { | ||
import refl._ | ||
import util._ | ||
import quoted.Toolbox.Default._ | ||
|
||
def isImplicitMethodType(tp: Type): Boolean = | ||
Type.IsMethodType.unapply(tp).flatMap(tp => if tp.isImplicit then Some(true) else None).nonEmpty | ||
|
||
cond.unseal.underlyingArgument match { | ||
case t @ Term.Apply(Term.Select(lhs, op), rhs :: Nil) => | ||
let(lhs) { left => | ||
let(rhs) { right => | ||
val app = Term.Select.overloaded(left, op, Nil, right :: Nil) | ||
let(app) { result => | ||
val l = left.seal[Any] | ||
val r = right.seal[Any] | ||
val b = result.seal[Boolean] | ||
val code = '{ scala.Predef.assert(~b) } | ||
code.unseal | ||
} | ||
} | ||
}.seal[Unit] | ||
case Term.Apply(f @ Term.Apply(Term.Select(Term.Apply(qual, lhs :: Nil), op), rhs :: Nil), implicits) | ||
if isImplicitMethodType(f.tpe) => | ||
let(lhs) { left => | ||
let(rhs) { right => | ||
val app = Term.Select.overloaded(Term.Apply(qual, left :: Nil), op, Nil, right :: Nil) | ||
let(Term.Apply(app, implicits)) { result => | ||
val l = left.seal[Any] | ||
val r = right.seal[Any] | ||
val b = result.seal[Boolean] | ||
val code = '{ scala.Predef.assert(~b) } | ||
code.unseal | ||
} | ||
} | ||
}.seal[Unit] | ||
} | ||
} | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
tests/run-with-compiler/reflect-select-constructor/test_2.scala
This file contains hidden or 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,29 @@ | ||
object Test { | ||
import scalatest._ | ||
|
||
case class Box[T](v: T) { | ||
def >(that: Box[T]): Boolean = this == that | ||
} | ||
|
||
trait EqInt | ||
implicit val eq: EqInt = new EqInt {} | ||
|
||
implicit class AnyOps[T](x: T) { | ||
def === (y: T)(implicit c: EqInt) = x == y | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
val a = Box(Some(10)) | ||
val five: Float = 5.0f | ||
val six: Double = 6.0 | ||
val ten: Int = 10 | ||
assert(a.v === Some(10)) | ||
assert(five < six) | ||
assert(five > 4) | ||
assert(ten > 5) | ||
assert(six < 7) | ||
assert(six > 5L) | ||
assert(Box(6) > Box(6)) | ||
assert(Box("h") > Box("h")) | ||
} | ||
} |
This file contains hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.