-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Opaque types do not work with match types #17211
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
Comments
The error message is not ideal--it would be better if it included the match trace--but there must be a compile error. |
Your expectations don't agree with each other. Because -- Error: foo.scala:14:26 ------------------------------------------------------
14 |def res5[Foo] = constValue[IsInt[Foo]]
| ^^^^^^^^^^^^^^^^^^^^^^
| not a constant type: IsInt[Foo]; cannot take constValue |
My point being (correct me if I'm wrong), that when we define an opaque type of I'm not sure if I'm trying to challenge the design decision here, but just stating that from my (very limited) experience, I cannot see why we would want to match an opaque type over the pattern ( type Dealias[T] = T // pseudocode
type IsInt[A] = A match
case Int => true
case Dealias[Int] => true // matches opaque types
case _ => false Here's the actual use case I where I stumbled upon it: type GetRequiredLabels[T <: Tuple] = T match
case Labelled[?, Option[?]] *: tail => GetRequiredLabels[tail]
case Labelled[IsSingleton[l], ?] *: tail => l *: GetRequiredLabels[tail]
case EmptyTuple => EmptyTuple I want to check exactly for that type. And if user for some reasons add an opaque type - the whole logic gets broken, while I expect that opaque types are well usual types. |
But aren't |
It is definitely not unrelated to |
Here's where what you say doesn't correspond: it's not known, statically, to be a subtype of
The difference between |
Ok, thanks for your input both, much appreciated. I think I'm going hold to my point of view that it's a better DX choice for the time being, but can't waste your time on the argument anymore. However, if we think it's an area of reporting, I find it odd that the compile-time error happens only when we try to materialize the constant type: type A = IsInt[Foo.Foo] // this is fine
constValue[A] // error is here However, if we construct another non-sense type: type IsIntOrString[A] = A match
case Int => "int"
case String => "string"
type B = IsIntOrString[Boolean] // error is here
constValue[B] // we don't even get here The error comes in much earlier, during type application and I don't see much difference between two cases. |
Yeah, I can see how that confusion. I think in the first release of match types they didn't error when they reduced to no matching, and user's preferred and asked for the eager error. The reason |
Could we extend the error message with a note saying that a match type could not be fully reduced, like we do in other places? Do you think that would be hard (c.f. appropriate for a spree)? |
I think it's possible. |
Scala features at hand here are:
|
@Maeeen @shivakg @iusildra as this is your first Spree, welcome! To get started hacking on the Dotty codebase, you will need to clone it, compile it and open it in VS Code using the following commands: git clone https://github.com/lampepfl/dotty.git
cd dotty
sbt compile
code . Then you will need to setup Metals to use the SBT build server. To do it, run the "Switch Build Server" VS Code command (by default the shortcut to open the VS Code command palette is ![]() ![]() To learn more: https://dotty.epfl.ch/docs/contributing/getting-started.html. |
Compiler version
3.3.0-RC3 and 3.2.2
Minimized code
Output
Expectation
I don't know if it should have been
true
orfalse
(probablyfalse
), but compilation error certainly wasn't expected. My expectation was that an opaque typeT
is treated as any otherT >: Nothing <: Any
.The text was updated successfully, but these errors were encountered: