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

SI-9745 typedFunction keeps x => f(x) #6007

Closed
wants to merge 1 commit into from

Conversation

som-snytt
Copy link
Contributor

To type x => f(x), typedFunction uses the expected
type and f to type x. Previously, it discarded the
result of typechecking f, which was a problem in the
case of a g(e) where e is "erroneous" but rewriteable
to an expr that checks, e.g., g(i += 1).

This commit keeps the rewritten g(i = i + 1) instead
of trying to recover the erroneous tree.

To type `x => f(x)`, `typedFunction` uses the expected
type and `f` to type `x`. Previously, it discarded the
result of typechecking `f`, which was a problem in the
case of a `g(e)` where `e` is "erroneous" but rewriteable
to an expr that checks, e.g., `g(i += 1)`.

This commit keeps the rewritten `g(i = i + 1)` instead
of trying to recover the erroneous tree.
// we can compare arguments and parameters by name because there cannot be a binder between
// the function's valdefs and the Apply's arguments
case Apply(meth, args) if (vparams corresponds args) { case (p, Ident(name)) => p.name == name case _ => false } =>
// We're looking for a method (as indicated by FUNmode in the silent typed below),
// so let's make sure our expected type is a MethodType
val methArgs = NoSymbol.newSyntheticValueParams(argpts map { case NoType => WildcardType case tp => tp })

val result = silent(_.typed(meth, mode.forFunMode, MethodType(methArgs, respt)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's explore keeping the silent and a variation of throwing in a .duplicate -> silent(_.typed(meth.duplicate, mode.forFunMode, MethodType(methArgs, respt))). That fixed the issue for me as well. I'm hesitant to drop the silent, but grant that duplication is costly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIRC there was a previous PR that duplicates? For some reason, it seemed simpler just to accept the unsilent judgment; but I don't spend all day with the code, and also I don't remember what I did last summer. Maybe this is an opportunity to try some jmh-driven development.

@adriaanm
Copy link
Contributor

I'm going to defer until M4, because I'm dubious on dropping silent, but my .duplicate suggestion may need more performance investigation than we can afford in time for M3.

@adriaanm adriaanm modified the milestones: 2.13.0-M3, 2.13.0-M4 Jan 12, 2018
@som-snytt
Copy link
Contributor Author

@adriaanm Sorry I haven't had a chance to get back to this. It doesn't take much to blow my lunchtime budget for FOSS. In 2018, though, I hope to get better at contributing review time, which is probably more useful than marginal repairs. (But please don't quote me; I'll probably delete this resolution next December.)

@adriaanm
Copy link
Contributor

adriaanm commented Aug 3, 2018

I'm pushing this to the RC, but I'm open to a refined fix either before (M5) or after (2.13.x)

@SethTisue
Copy link
Member

needs rebase

adriaanm added a commit to adriaanm/scala that referenced this pull request Oct 5, 2018
adriaanm added a commit to adriaanm/scala that referenced this pull request Oct 5, 2018
test case taken from original PR (scala#6007)
@adriaanm
Copy link
Contributor

adriaanm commented Oct 5, 2018

Adopting as #7316

@adriaanm adriaanm closed this Oct 5, 2018
@som-snytt
Copy link
Contributor Author

@adriaanm I have a few other jobs around the house I've been meaning to tackle, if you have time.

@SethTisue SethTisue removed this from the 2.13.0-RC1 milestone Oct 5, 2018
@adriaanm
Copy link
Contributor

adriaanm commented Oct 5, 2018 via email

adriaanm added a commit to adriaanm/scala that referenced this pull request Oct 8, 2018
Do more for typedFunction of eta-expanded method:
keep typed method selection (fix scala/bug#9745, follow up for scala#6007)

Test case taken from original PR.
adriaanm added a commit to adriaanm/scala that referenced this pull request Oct 15, 2018
Do more for typedFunction of eta-expanded method:
keep typed method selection (fix scala/bug#9745, follow up for scala#6007)

Test case taken from original PR.

Backported from 64d4c24
adriaanm added a commit to adriaanm/scala that referenced this pull request Oct 15, 2018
Do more for typedFunction of eta-expanded method:
keep typed method selection (fix scala/bug#9745, follow up for scala#6007)

Test case taken from original PR.

Backported from 64d4c24
@som-snytt som-snytt deleted the issue/9745-2.13 branch December 20, 2020 00:33
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