-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Cant use compiletime.ops.any.== with String when type of a value #8392
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
Comparing string literals is a legitimate thing to do, so can't this be fixed by changing the signature of |
what would you say for this case, is the left side of scala> import compiletime.ops.int._
scala> class Foo
// defined class Foo
scala> summon[Foo * Foo =:= 0]
1 |summon[Foo * Foo =:= 0]
| ^
|Cannot prove that Foo * Foo =:= (0 : Int)..
|I found:
|
| <:<.refl[Nothing]
|
|But method refl in object <:< does not match type Foo * Foo =:= (0 : Int). |
Honestly no idea, but that's a separate problem from getting |
updated the context |
If the parameter type bounds change to |
Yeah, so we could also just have no bounds at all if that's simpler. |
It's better to have no bounds at all in this context, or to change |
It is my intention to update the singleton-ops library to dotty, so it will take of combining generic |
Moving them to type-specific subpackages means that we lose the ability to do |
I actually thought |
I don't think that is useful, but again in singleton-ops I will be able to do type ==[L, R] <: Boolean = (L, R) match {
case (Int, Int) => int.==[L, R]
case (String, String) => string.==[L, R]
case (Int, String) => string.==[string.ToString[L], R]
} |
@MaximeKjaer Can you take care of making a PR for this ? |
Yep, no problem. I'll make a PR later tonight. |
`scala.compiletime.ops.any.==` is incorrectly constrained to subtypes of `AnyVal`, which prevents it working with `String` literal types. This change: - changes the constraint from `AnyVal` to `Singleton` - improves testing. A quick note about the tests. As far as I can tell they didn't actually check much. The tests were in the `neg` directory without a `check` file so it was irrelevant if they compiled or not. My change includes moving the compiling tests into the `run` directory, thus ensuring they must compile for the test to pass, as well as adding cases for `String` literal types to both success and failure cases. I'm currently have a strange issue where Dotty thinks my `check` file only expects 8 error though it clearly has 10 errors, and thus fails the test. Closes scala#8392
I have implemented most of a fix, which may be useful: https://github.com/noelwelsh/dotty/tree/bugfix-singleton-ops-8392 The commit comment details what I have done. I think the most important part of my change is what I have done to the tests. As far as I can tell from the Dotty documentation and my own experiments the existing tests were not actually performing any testing. Which is to say the test would pass regardless of the type tests succeeding or failing. |
Dotty's testing infrastructure looks for |
I see. That would explain why my tests are failing. |
It seems to me that there is something slightly broken about how errors are handled in compiletime ops. Here is the example from #8271 that fails because the bounds of import scala.compiletime.ops.any._
val eq3: "1" == "1" = true
// -- [E057] Type Mismatch Error: tests/neg/singleton-ops-any.scala:2:9 -----------
// 2 |val eq3: "1" == "1" = true
// | ^
// | Type argument ("1" : String) does not conform to upper bound AnyVal
// -- [E057] Type Mismatch Error: tests/neg/singleton-ops-any.scala:2:16 ----------
// 2 |val eq3: "1" == "1" = true
// | ^
// | Type argument ("1" : String) does not conform to upper bound AnyVal
// 2 errors found However, it seems that the type-level constant fold still is taking place, as assigning import scala.compiletime.ops.any._
val eq3: "1" == "1" = false
// -- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:2:22 ----------
// 2 |val eq3: "1" == "1" = false
// | ^^^^^
// | Found: (false : Boolean)
// | Required: (true : Boolean)
// 1 error found In fact, if there is another type mismatch error in the file, the fact that import scala.compiletime.ops.any._
val eq2: 1 == 2 = true
val eq3: "1" == "1" = true
// -- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:4:20 ----------
// 4 | val eq2: 1 == 2 = true
// | ^^^^
// | Found: (true : Boolean)
// | Required: (false : Boolean)
// 1 error found With no type bounds on the parameters of |
Fixes scala#8392 String is not a subtype of AnyVal, so the type `==["", ""]` could not be applied. No type bound is preferable to a type bound of `Singleton` as it maintains the ability to have an unapplied type `Int == Int`, and is more in line with the `any` package name.
Fixes scala#8392 String is not a subtype of AnyVal, so the type `==["", ""]` could not be applied. No type bound is preferable to a type bound of `Singleton` as it maintains the ability to have an unapplied type `Int == Int`, and is more in line with the `any` package name.
Fix #8392: Remove parameter type bounds from scala.compiletime.ops.any types
Uh oh!
There was an error while loading. Please reload this page.
minimized code
expectation
EDIT: the second example behaves according to its definition of
type ==[X <: AnyVal, Y <: AnyVal] <: Boolean
. However it should behave like the first. The type signature should be changed so thatt
can be typedThe text was updated successfully, but these errors were encountered: