Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

For migration to 3, accommodate case companion as function#10648

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
lrytz merged 4 commits intoscala:2.13.xfromsom-snytt:issue/3664-case-function
Feb 5, 2024

Conversation

@som-snytt
Copy link
Contributor

@som-snyttsom-snytt commentedJan 2, 2024
edited
Loading

Scala 2 sometimes makes the companion object of a case class extendFunction; Scala 3 does not, but includes other adaptations which are backported under-Xsource:3-cross and allow the following idioms with reduced ceremony:

case class B(i: Int)case class C(i: Int, j: Int)def mapped(xs: List[Int]): List[B] = xs.map(B)def cross(xs: List[(Int, Int)]): List[C] = xs.map(C)def f(xs: List[(Int, Int)]): List[C] = xs.map(C.tupled)def g(xs: List[Int]): List[C] = xs.map(C.curried).map(_(42))

Under-Xsource:3, using the case class companion as a function will warn.

Backports Dotty migration support of case class companions by insertingapply. Dotty does not automatically addFunction as a parent of the companion; for Scala 2 under-Xsource:3-cross, follow Dotty but also adapt where the companion is not already aFunction.

Since Scala 2 lacks parameter untupling, also support explicitC.tupled and for completenessC.curried.

Fixesscala/bug#3664

He-Pin reacted with thumbs up emojijoroKr21, He-Pin, and sideeffffect reacted with heart emoji
@scala-jenkinsscala-jenkins added this to the2.13.14 milestoneJan 2, 2024
@som-snyttsom-snytt modified the milestones:2.13.14,2.13.13Jan 2, 2024
@joroKr21
Copy link
Member

Oh wait, why add a feature that is deprecated right away? 🤔

@som-snytt
Copy link
ContributorAuthor

Not sure about knobs for enablement yet, but Scala 3 warns about apply insertion. It's strictly a migration mitigation.

@som-snytt
Copy link
ContributorAuthor

blocked by#10573

Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

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

LGTM 👍 thanks!

@joroKr21
Copy link
Member

Not sure about knobs for enablement yet, but Scala 3 warns about apply insertion. It's strictly a migration mitigation.

C.apply works both in Scala 2 and Scala 3 right?

@som-snytt
Copy link
ContributorAuthor

@joroKr21 iirc the tupled case is not handled because scala 2 doesn't do parameter untupling adaptation. I'll try to nail it down while polishing.

The other missing parts are compose & andThen, so the adaptation here is incomplete in that sense. So really, we're just trying to make it easier for those slick users. I used slick once, do I have to try it again to test out the use case? 😿

joroKr21 reacted with laugh emoji

@som-snytt
Copy link
ContributorAuthor

som-snytt commentedJan 4, 2024
edited
Loading

@lrytz about to contribute a bit of doc for the incompatibility matrix as you pointed out.

I haven't tried it, but maybe it makes sense to supportcase class D(i: Int, j: Int); List(42->27).map(D) directly, by injection oftupled, where the syntax is the same as Scala 3 but the mechanism is slightly different.

It was interesting that the recommended idiom is what is implemented here.(Foo.apply _).curried(1)(true)

@lrytz
Copy link
Member

maybe it makes sense to supportcase class D(i: Int, j: Int); List(42->27).map(D) directly

Since this doesn't currently work on Scala 2, and only works in Scala 3 with a warning and is therefore discouraged, I don't think this is needed.

@som-snytt
Copy link
ContributorAuthor

som-snytt commentedJan 4, 2024
edited
Loading

My case fortupled injection is cross-compilation. For the tupled case, it requires different sources becauseD.tupled is not supported by Scala 3. I haven't tried slick use case yet, but it's the tupled case they care about. I assume slick supports Scala 3.

Since this doesn't currently work on Scala 2, and only works in Scala 3 with a warning and is therefore discouraged, I don't think this is needed.

Also, as@joroKr21 pointed out, this is true of everything in this PR. It has limited shelf life, as was true for the Scala 3 feature when it was introduced recently.

@lrytz
Copy link
Member

OK, good point

@som-snyttsom-snytt marked this pull request as ready for reviewJanuary 6, 2024 17:19
@som-snytt
Copy link
ContributorAuthor

Not sure I'll get around to tupled.

@SethTisueSethTisue added the release-notesworth highlighting in next release notes labelJan 18, 2024
@SethTisueSethTisue self-assigned thisJan 18, 2024
@SethTisueSethTisue modified the milestones:2.13.13,2.13.14Jan 22, 2024
@SethTisueSethTisue removed their assignmentJan 22, 2024
@SethTisue

This comment was marked as resolved.

@som-snyttsom-snyttforce-pushed theissue/3664-case-function branch 2 times, most recently fromd1986de to0996ac6CompareJanuary 30, 2024 18:16
Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

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

LGTM once the details are worked out

@som-snyttsom-snyttforce-pushed theissue/3664-case-function branch frome897b8a to751a250CompareJanuary 31, 2024 19:51
@som-snytt

This comment was marked as resolved.

Copy link
Member

@lrytzlrytz left a comment

Choose a reason for hiding this comment

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

This LGTM, let me know if you want to add anything or we can merge.

@SethTisueSethTisue modified the milestones:2.13.14,2.13.13Feb 1, 2024
@som-snytt
Copy link
ContributorAuthor

som-snytt commentedFeb 1, 2024
edited
Loading

@lrytz added a commit for "insert apply with tupling adaptation". It's a bit tricky (subtle), so it is unsquashed.

I re-enabled the lrytz maneuver for your convenience. (Feel free to push here again.)

Perhaps there is better API usage for the simple questions inadaptApplyInsertion, such as "does it have an apply method and does its arity match the expected type or the tuple param", etc.

Slightly augmented tests. My takeaway vis-a-vis TDD is that for a code change of a certain complexity, discipline is required to add tests for intersecting cases. I don't evince that discipline here. A nice IDE tool would be a test generator that probes feature interactions, scalacheck + fuzzing + chatgpt. It's nice to have the community build, but we could use the corpus to generate targeted tests (because we know how people use case classes and tupled, for instance). Oh, I just thought of another test.

Edit: I checked thatabstract case class (so there is no apply) shows the same error as arity mismatch,found C.type. In fact,without this commit it SOs. I checked out the parent commit and tried it standalone, it errors correctly.

@som-snyttsom-snyttforce-pushed theissue/3664-case-function branch from393e77e tod8958d0CompareFebruary 2, 2024 17:32
@som-snytt
Copy link
ContributorAuthor

som-snytt commentedFeb 2, 2024
edited
Loading

Rebased and added support forcase class E() (which is adapted by dotty).

The first typecheck ofC.apply uses pt (so E works). On error, use wildcard (so tupled works).

Note: using wildcard first emits spurious warning about "empty application" ofE(). Even though the result is discarded by us, the successful result makes silent emit the warnings. (Possibly you couldtyper.context.reporter.clearAll() before returning from the silent op, but it's clunky.)

Also added test for overloaded apply. Instead of erroring nicely, it just works because expected type is used first.

@som-snyttsom-snyttforce-pushed theissue/3664-case-function branch fromd8958d0 tof57bef9CompareFebruary 2, 2024 17:54
@som-snytt

This comment was marked as resolved.

@som-snytt
Copy link
ContributorAuthor

/rebuild

@SethTisue
Copy link
Member

wasn't sure if/rebuild does older commits (the ones that the "combined" check is complaining about), but I see athttps://scala-ci.typesafe.com/job/scala-2.13.x-validate-main/ that it does

@som-snytt

This comment was marked as resolved.

@som-snytt

This comment was marked as resolved.

@lrytz

This comment was marked as resolved.

lrytz

This comment was marked as resolved.

@lrytzlrytz merged commit521cb82 intoscala:2.13.xFeb 5, 2024
@som-snyttsom-snytt deleted the issue/3664-case-function branchFebruary 6, 2024 00:41
@SethTisue
Copy link
Member

SethTisue commentedFeb 10, 2024
edited
Loading

@som-snytt can you do a round of making the PR description user-facing? I think it would be valuable to include an example, and to explicitly say what the behavior is on-Xsource:3 vs-Xsource:3-cross vs neither.

@SethTisueSethTisue changed the titleAccommodate case companion as functionFor migration to 3, accommodate case companion as functionFeb 10, 2024
@som-snytt
Copy link
ContributorAuthor

I'll try to nail it down while polishing.

The pun was 💅 .

SethTisue and lrytz reacted with laugh emoji

@lrytz
Copy link
Member

9 months and noone noticed...

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lrytzlrytzlrytz approved these changes

Assignees

No one assigned

Labels

release-notesworth highlighting in next release notes

Projects

None yet

Milestone

2.13.13

Development

Successfully merging this pull request may close these issues.

explicit case class companion does not extend Function / override toString

5 participants

@som-snytt@joroKr21@lrytz@SethTisue@scala-jenkins

[8]ページ先頭

©2009-2025 Movatter.jp