Skip to content

Fix #5144: Avoid Expr of method type #5154

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
merged 1 commit into from
Sep 26, 2018

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Sep 25, 2018

Change the type of lifted method references to function types and
allow method references in Holes.

@nicolasstucki nicolasstucki changed the title Fix #5144 Fix #5144: Avoid Expr of method type Sep 25, 2018
Change the type of lifted method references to function types and
allow method references in Holes.
@smarter
Copy link
Member

smarter commented Sep 26, 2018

You could enforce this invariant by adding assert(resType.isValueTypeOrWildcard, resType.toString) in the constructor of ExprType, similarly to what is done in OrType and AndType.

Copy link
Contributor

@liufengyun liufengyun left a comment

Choose a reason for hiding this comment

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

Otherwise, LGTM

def eval1(ff: Expr[Int => Int]): Expr[Int] = '((~ff)(42))

def peval1(): Expr[Unit] = '{
def f(x: Int): Int = ~eval1('(f))
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a curiosity: we do eta-expansion for methods when the expected type is a function, so that a method is always applied. In this case of quotes, it seems it breaks this invariant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is unrelated with the eta-expansion. This is about lifting a tree that represents a reference to a method that is outside the quote. It could not come from eta-expansion the code above could be def f(x: Int): Int = ~eval1('{ f(1); 2 }) where f also needs lifting.

@nicolasstucki
Copy link
Contributor Author

@smarter I dont see the relation with ExprType, these where generating types such as scala.quoted.Expr[(x: Int): Int].

@smarter
Copy link
Member

smarter commented Sep 26, 2018

I see, so there's a typeapply where the argument is a methodtype? There could be an assertion to check for that too

@nicolasstucki
Copy link
Contributor Author

Yes. I will add an assertion.

@nicolasstucki
Copy link
Contributor Author

The conditions for the assertion in AppliedType are more complex and may add unwanted overhead. Let's explore the invariants of the types and how to check them in a separate PR.

@nicolasstucki nicolasstucki merged commit c17dda0 into scala:master Sep 26, 2018
@nicolasstucki nicolasstucki deleted the fix-#5144 branch September 26, 2018 18:08
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.

3 participants