-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Fix #21402: Always allow type member extraction for stable scrutinees in match types. #21700
Merged
Merged
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 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 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,41 @@ | ||
abstract class AbstractServiceKey: | ||
type Protocol | ||
|
||
abstract class ServiceKey[T] extends AbstractServiceKey: | ||
type Protocol = T | ||
|
||
type Aux[P] = AbstractServiceKey { type Protocol = P } | ||
type Service[K <: Aux[?]] = K match | ||
case Aux[t] => ActorRef[t] | ||
type Subscriber[K <: Aux[?]] = K match | ||
case Aux[t] => ActorRef[ReceptionistMessages.Listing[t]] | ||
|
||
trait ActorRef[-T] | ||
|
||
object ReceptionistMessages: | ||
final case class Listing[T](key: ServiceKey[T]) | ||
|
||
class TypedMultiMap[T <: AnyRef, K[_ <: T]]: | ||
def get(key: T): Set[K[key.type]] = ??? | ||
transparent inline def getInlined(key: T): Set[K[key.type]] = ??? | ||
inline def inserted(key: T, value: K[key.type]): TypedMultiMap[T, K] = ??? | ||
|
||
object LocalReceptionist { | ||
final case class State( | ||
services: TypedMultiMap[AbstractServiceKey, Service], | ||
subscriptions: TypedMultiMap[AbstractServiceKey, Subscriber] | ||
): | ||
def testInsert(key: AbstractServiceKey)(serviceInstance: ActorRef[key.Protocol]): State = { | ||
val fails = services.inserted(key, serviceInstance) // error | ||
??? | ||
} | ||
|
||
def testGet[T](key: AbstractServiceKey): Unit = { | ||
val newState: State = ??? | ||
val fails: Set[ActorRef[key.Protocol]] = newState.services.get(key) // error | ||
val works: Set[ActorRef[key.Protocol]] = newState.services.getInlined(key) // workaround | ||
|
||
val fails2: Set[ActorRef[ReceptionistMessages.Listing[key.Protocol]]] = newState.subscriptions.get(key) // error | ||
val works2: Set[ActorRef[ReceptionistMessages.Listing[key.Protocol]]] = newState.subscriptions.getInlined(key) // workaround | ||
} | ||
} |
This file contains 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,27 @@ | ||
// Test that match types can extract path-dependent abstract types out of singleton types | ||
|
||
trait Base: | ||
type Value | ||
|
||
def getValue(): Value | ||
def setValue(v: Value): Unit | ||
end Base | ||
|
||
object Extractor: | ||
type Helper[X] = Base { type Value = X } | ||
|
||
type Extract[B <: Base] = B match | ||
case Helper[x] => x | ||
end Extractor | ||
|
||
object Test: | ||
import Extractor.Extract | ||
|
||
/* As is, this is a bit silly, since we could use `b.Value` instead. However, | ||
* in larger examples with more indirections, it is not always possible to | ||
* directly use the path-dependent version. See i21402 for a real-world use | ||
* case. | ||
*/ | ||
def foo(b: Base): Extract[b.type] = b.getValue() | ||
def bar(b: Base, v: Extract[b.type]): Unit = b.setValue(v) | ||
end Test |
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 looks similar to Type#bounds. That might or might not be appropriate here, but wanted to bring it to your attention.