-
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
Operations on NamedTuples do not work with singleton types due to match type refusing to reduce #20453
Comments
Yes, widening singleton types of paths that can be substituted later creates established unsoundness issues. See #19746 |
Thanks for the reference. A possibly viable workaround is to use a wrapper type: import scala.language.experimental.namedTuples
class Wrapper[T](x: T)
object Wrapper:
type Extract[W <: Wrapper[?]] = W match
case Wrapper[t] => t
object Test:
val f: (name: String, age: Int) = ???
val f2 = Wrapper(f)
val x: NamedTupleDecomposition.Names[Wrapper.Extract[f2.type]] = ("name", "age") Not sure if there's a better way or if that can help suggest some more systematic fix. |
@smarter what if we explicitly create a |
That would reopen the soundness hole of #19746 if |
I'm not sure that will happen, because of the lazy nature of singleton ops operations. |
Though note that the fix for #19746 (0a3497b) specifically target singleton types coming from parameters (since those can be substituted), so maybe something like a |
Indeed: #20515. |
Compiler version
7d559ad
Minimized code
Output
Expectation
I'd expect this to reduce, otherwise all NamedTuple operations that use
NamedTupleDecomposition
likeNamedTuple.Map
will fail to reduce on singleton types. NamedTupleDecomposition is defined as:So NamedTuple is treated as an abstract type constructor and we end up in
scala3/compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Lines 3506 to 3511 in 7d559ad
Which fails since the scrutinee isn't widened. @sjrd : do you anticipate a soundness issue if we added a
.widenSingleton
on the scrutinee here? Or is the whole design of NamedTupleDecomposition doomed?The text was updated successfully, but these errors were encountered: