Skip to content
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

Evaluate flow control #472

Merged
merged 4 commits into from
Jul 5, 2023
Merged

Conversation

iusildra
Copy link
Contributor

Allows to evaluate (and eventually pre-evaluate) flow control at runtime. For instance

case class Test(i: Int)
def test(t: Test) = s"test ${t.i}"

if (true) 1 else 2                    // res0: Int = 1
(if (true) Test(1) else Test(2)).i    // res1: Int = 1
(if (true) Test(1) else 2).i          // res2: Int = 1 thanks to pre-evaluation
test(if(true) Test(1) else 1)         // res3: String = "test 1"
(if (m()) Test(1) else 2).i          // fails because the `if` cannot be pre-evaluated

@iusildra iusildra marked this pull request as ready for review July 3, 2023 10:17
@@ -26,19 +26,20 @@ protected[internal] object RuntimeEvaluatorExtractors {
}

object MethodCall {
def unapply(tree: RuntimeTree): Option[RuntimeTree] =
def unapply(tree: RuntimeTree): Boolean =
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is not an extractor (it returns a Boolean), it should not be called unapply.

@adpi2 adpi2 merged commit 093dcc7 into scalacenter:main Jul 5, 2023
9 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants