From c4f9e60872cdea143d45eab00445abefceab669e Mon Sep 17 00:00:00 2001 From: Maxime Kjaer Date: Tue, 14 Apr 2020 22:42:27 +0200 Subject: [PATCH] Remove parameter type bounds from scala.compiletime.ops.any Fixes #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. --- .../src/scala/compiletime/ops/package.scala | 4 ++-- tests/neg/singleton-ops-any.check | 20 +++++++++++++++++++ tests/neg/singleton-ops-any.scala | 1 + 3 files changed, 23 insertions(+), 2 deletions(-) create mode 100644 tests/neg/singleton-ops-any.check diff --git a/library/src/scala/compiletime/ops/package.scala b/library/src/scala/compiletime/ops/package.scala index ea9fdbd942cc..e272f6cb04e9 100644 --- a/library/src/scala/compiletime/ops/package.scala +++ b/library/src/scala/compiletime/ops/package.scala @@ -11,7 +11,7 @@ package object ops { * val eq3: "1" == "1" = true * ``` */ - @infix type ==[X <: AnyVal, Y <: AnyVal] <: Boolean + @infix type ==[X, Y] <: Boolean /** Inequality comparison of two singleton types. * ```scala @@ -20,7 +20,7 @@ package object ops { * val eq3: "1" != "1" = false * ``` */ - @infix type !=[X <: AnyVal, Y <: AnyVal] <: Boolean + @infix type !=[X, Y] <: Boolean } object string { diff --git a/tests/neg/singleton-ops-any.check b/tests/neg/singleton-ops-any.check new file mode 100644 index 000000000000..a497686284af --- /dev/null +++ b/tests/neg/singleton-ops-any.check @@ -0,0 +1,20 @@ +-- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:6:23 -------------------------------------------------- +6 | val t34: 10 == "5" = true // error + | ^^^^ + | Found: (true : Boolean) + | Required: (false : Boolean) +-- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:7:22 -------------------------------------------------- +7 | val t35: 10 == 10 = false // error + | ^^^^^ + | Found: (false : Boolean) + | Required: (true : Boolean) +-- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:12:24 ------------------------------------------------- +12 | val t38: false != 5 = false // error + | ^^^^^ + | Found: (false : Boolean) + | Required: (true : Boolean) +-- [E007] Type Mismatch Error: tests/neg/singleton-ops-any.scala:13:22 ------------------------------------------------- +13 | val t39: 10 != 10 = true // error + | ^^^^ + | Found: (true : Boolean) + | Required: (false : Boolean) diff --git a/tests/neg/singleton-ops-any.scala b/tests/neg/singleton-ops-any.scala index 959393bbc820..2f4112dbe5e1 100644 --- a/tests/neg/singleton-ops-any.scala +++ b/tests/neg/singleton-ops-any.scala @@ -5,6 +5,7 @@ object Test { val t33: 0 == false = false val t34: 10 == "5" = true // error val t35: 10 == 10 = false // error + val t35string: "10" == "10" = true val t36: 1 != 1 = false val t37: 0 != 1 = true