-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Allow appliedToTypeTrees to operate on block expressions
#26259
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
Open
SolalPirelli
wants to merge
1
commit into
scala:main
Choose a base branch
from
dotty-staging:solal/26238
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+88
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| trait Thing[T] | ||
| trait G | ||
|
|
||
| object Outer: | ||
|
|
||
| def thing: Thing[Int] = ??? | ||
|
|
||
| extension[T1](t: Thing[T1])(using g: G = new G { }) | ||
| def map[T2](m: T1 => T2): Thing[T2] = ??? | ||
| def flatMap[T2](m: T1 => Thing[T2]): Thing[T2] = ??? | ||
|
|
||
| // `y` requires a `flatMap`, and that one requires getting the default value for the `g` argument, | ||
| // and getting that default value requires the `t` argument (since default values can depend on previous args), | ||
| // which means we end up with a block; | ||
| // and since the whole thing is generic, we must apply a generic type argument to that block | ||
| for | ||
| x <- thing | ||
| y <- thing | ||
| yield | ||
| 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| object toplevel { | ||
|
|
||
| @deprecated("pls work this out") | ||
| def ??? = scala.Predef.`???` | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we at least remove dead code from the non-minimized test? |
||
|
|
||
| import util.ChainingOps.{*, given} | ||
|
|
||
| object S { | ||
|
|
||
| trait AllocatedNodeTypeFamily: | ||
| type Node | ||
|
|
||
| trait Parser[+A] private[S] () : | ||
| type SpcNd | ||
|
|
||
| type OutliningParser[+A, +Node] | ||
| = Parser[A] { type SpcNd <: Node } | ||
|
|
||
| extension [R1] (g1: Parser[R1] ) | ||
| (using pfmoIspcndi: ParserFlatMapOp.ISpcNdInvariant = new ParserFlatMapOp.ISpcNdInvariant {}.asInstanceOf[ParserFlatMapOp.ISpcNdInvariant { type SpcNdObj = g1.SpcNd } ] ) | ||
|
|
||
| def map[R2] (m: R1 => ( R2 ) ): OutliningParser[R2, g1.SpcNd] = new Parser[Any] {}.asInstanceOf | ||
| def flatMap[R2] (m: R1 => (Parser[R2] ) ): OutliningParser[R2, g1.SpcNd] = new Parser[Any] {}.asInstanceOf | ||
|
|
||
| object ParserFlatMapOp { | ||
|
|
||
| given given_ISpcNdInvariant_PModAllocatedNodeTypeFamily | ||
| : (x: AllocatedNodeTypeFamily ) => (ISpcNdInvariant { type SpcNdObj = x.Node }) | ||
| = new ISpcNdInvariant {}.asInstanceOf | ||
|
|
||
| trait ISpcNdInvariant : | ||
| type SpcNdObj | ||
|
|
||
| } // ParserFlatMapOp. | ||
|
|
||
| def defaultIntParser | ||
| : Parser[Int] | ||
| = new Parser[Any] {}.asInstanceOf | ||
|
|
||
| } // S. | ||
|
|
||
| System.err.println(Math.random() ) | ||
|
|
||
| System.err.println(Math.random() ) | ||
|
|
||
| locally : | ||
| System.err.println(Math.random() ) | ||
|
|
||
| // given S.ParserFlatMapOp.ISpcNdInvariant | ||
| // = (new S.ParserFlatMapOp.ISpcNdInvariant {}).asInstanceOf | ||
|
|
||
| /* run locally you might see something like say "unexpected tree for type application" or the like.. 😒 */ | ||
| /* commented out, the whole code would compile and run like it should.. */ | ||
| locally : | ||
| for | ||
| r1 <- S.defaultIntParser | ||
| r2 <- S.defaultIntParser | ||
| yield { 5 } | ||
| .toString() | ||
|
|
||
| System.err.println(s"done.") | ||
|
|
||
| System.err.println(Math.random() ) | ||
|
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix is suspicious. What if it's an
Ifwhere the two branches need a type application? What is it aboutBlocks that deserves a special-case here, but not other constructs? Also why do this for type arguments but not term arguments?If there is a specific call site that for some reason creates a
Block, then that call site is probably the correct place to take care of it.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree it's not an amazing fix, but the bit where a Block is created seems quite far from this, and I don't see a way to not create a Block there given the need for a temp local to use the argument twice (once as an arg, once as an arg of the default value function of the using)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not saying the call site should not create a
Block. But when it creates aBlock, it should make sure to push any type application inside the block itself.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
Blockis created intypedUnadapted, and this method here is called inadapt, both from the bit oftypedthat doesadapt(typedUnadapted(...), ...).I agree in principle we shouldn't have to add a special case here but I don't see how to avoid it without changing a lot of logic.