Skip to content

Disallow synthesized lambdas in statement position #11769

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 7 commits into from
Mar 17, 2021

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 16, 2021

Disallow lambdas in statement position or if the expected type is Unit. This was a loophole that opened up due to the changes to eta expansion in Scala 3. We did get a warning in these cases, but an error might be better.

Fixes #11761

odersky added 4 commits March 17, 2021 10:17
Disallow lambdas in statement position or if the expected type is Unit.

Fixes scala#11671
For user-written lambdas, presumably the devs know what they are doing. User-written
numbers aappear in quite a lot of test cases.

A second change of this commit is that closure methods now get a more accurate span.
There are two utest tests that fail. Unfortunately the assertions fail without
any info and I don't know enough about utest to figure out what went wrong. Somebody
who knows utest should follow up on this.
@odersky
Copy link
Contributor Author

odersky commented Mar 17, 2021

This looks like a simple fix that makes sense, but it has been nightmarish since it seems all testing frameworks hate me now.

There are two utest tests that fail where I am stuck. Unfortunately the assertions fail without
any info and I don't know enough about utest to figure out what went wrong. So I had to disable
the test. Who knows enough about utest to follow up on this?

@odersky
Copy link
Contributor Author

odersky commented Mar 17, 2021

The latest iteration of this does allow user-defined lambdas in statement position even though they don't make sense since
all testing suites rely on this heavily. So what we do is to try to flag as errors just synthetic lambdas that arise from eta expansion or other operations. The problem is how to to detect these lambdas. That has been super tricky. Not for user-defined code, there it is simple, but for code that test frameworks make up themselves.

Copy link
Contributor

@abgruszecki abgruszecki left a comment

Choose a reason for hiding this comment

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

LGTM!

@odersky odersky merged commit 8fcce8f into scala:master Mar 17, 2021
@odersky odersky deleted the fix-11761 branch March 17, 2021 21:43
griggt added a commit to griggt/dotty that referenced this pull request Mar 25, 2021
@griggt
Copy link
Contributor

griggt commented Mar 25, 2021

There are two utest tests that fail where I am stuck. Unfortunately the assertions fail without any info and I don't know enough about utest to figure out what went wrong. So I had to disable the test. Who knows enough about utest to follow up on this?

I took a look and proposed a fix in #11887.

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.

Eta expansion undesirable when result will be immediately discarded
4 participants