Skip to content

Add tasty seal methods #5603

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 3 commits into from
Dec 13, 2018
Merged

Conversation

nicolasstucki
Copy link
Contributor

@nicolasstucki nicolasstucki commented Dec 12, 2018

No description provided.

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.

It is a great addition to support sealing methods as functions 🎉

val closureResType = mtpe.resType match {
case t: MethodType => t.toFunctionType()
case t => t
}
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems this does handle param blocks > 2?

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 was working properly but did not fully convert to the lambda type. I changed toFunctionType to make sure it never leaves MethodTypes as result type.

case 0 => pre.seal[() => Any].apply().unseal
case 1 => pre.seal[Int => Any].apply('(0)).unseal
case 2 => pre.seal[(Int, Int) => Any].apply('(0), '(0)).unseal
case 3 => pre.seal[(Int, Int, Int) => Any].apply('(0), '(0), '(0)).unseal
Copy link
Contributor

Choose a reason for hiding this comment

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

If I understand correctly, this approach will create an unnecessary closure?

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 will create the extra closure, but when the apply is called directly on the seals expression it is beta reduced straight away.

Without this change we got types like `Int => (n: Int): Int`, now we get `Int => Int => Int`.
The first type happened to work fine but is not consistent.
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.

The last commit LGTM

@liufengyun liufengyun merged commit 9b192c4 into scala:master Dec 13, 2018
@liufengyun liufengyun deleted the add-tasty-seal-methods branch December 13, 2018 16:22
@biboudis biboudis added this to the 0.12 Tech Preview milestone Jan 18, 2019
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.

4 participants