-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better wildcard approximations of higher-kinded applications
- Loading branch information
Showing
7 changed files
with
68 additions
and
57 deletions.
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
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 |
---|---|---|
@@ -1,36 +1,20 @@ | ||
-- [E007] Type Mismatch Error: tests/neg/i15998.scala:11:23 ------------------------------------------------------------ | ||
11 | RingSeq.isRotationOf("DAB") // error | ||
| ^^^^^ | ||
| Found: ("DAB" : String) | ||
| Required: CC[A] | ||
-- [E007] Type Mismatch Error: tests/neg/i15998.scala:6:12 ------------------------------------------------------------- | ||
6 |val _ = foo(1) // error | ||
| ^ | ||
| Found: (1 : Int) | ||
| Required: CC[A] | ||
| | ||
| where: A is a type variable | ||
| CC is a type variable with constraint <: [B] =>> Any | ||
| | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than CC[A] | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- Error: tests/neg/i15998.scala:11:11 --------------------------------------------------------------------------------- | ||
11 |val _ = bar // error | ||
| ^ | ||
| No implicit search was attempted for parameter x of method bar | ||
| since the expected type X is not specific enough | ||
| | ||
| where: A is a type variable | ||
| CC is a type variable with constraint <: [B] =>> collection.SeqOps[B, CC, CC[B]] | ||
| | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than CC[A] | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E008] Not Found Error: tests/neg/i15998.scala:12:9 ----------------------------------------------------------------- | ||
12 | "ABCD".isRotationOf("DAB") // error | ||
| ^^^^^^^^^^^^^^^^^^^ | ||
| value isRotationOf is not a member of String. | ||
| An extension method was tried, but could not be fully constructed: | ||
| | ||
| RingSeq.isRotationOf[A, CC]("ABCD") failed with | ||
| | ||
| Found: ("ABCD" : String) | ||
| Required: CC[A] | ||
| | ||
| where: A is a type variable | ||
| CC is a type variable with constraint <: [B] =>> collection.SeqOps[B, CC, CC[B]] | ||
| | ||
| Note that implicit conversions were not tried because the result of an implicit conversion | ||
| must be more specific than CC[A] | ||
-- Error: tests/neg/i15998.scala:21:13 --------------------------------------------------------------------------------- | ||
21 | val x = foo // error | ||
| ^ | ||
| No implicit search was attempted for parameter x of method foo | ||
| since the expected type X is too unspecific | ||
| | ||
| where: X is a type variable | ||
| where: X is a type variable |
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 |
---|---|---|
@@ -1,21 +1,11 @@ | ||
import scala.collection.SeqOps | ||
|
||
trait ComparingOps: | ||
extension[A, CC[B] <: SeqOps[B, CC, CC[B]]](ring: CC[A]) | ||
def isRotationOf(that: CC[A]): Boolean = ??? | ||
given split: Conversion[Int, List[Int]] = ??? | ||
|
||
object RingSeq extends ComparingOps | ||
import RingSeq.* | ||
def foo[A, CC[B]](ring: CC[A]): Unit = () | ||
|
||
@main def Test = | ||
RingSeq.isRotationOf("DAB") // error | ||
"ABCD".isRotationOf("DAB") // error | ||
val _ = foo(1) // error | ||
|
||
// workaround | ||
RingSeq.isRotationOf[Char, IndexedSeq]("DAB") | ||
RingSeq.isRotationOf(wrapString("DAB")) | ||
wrapString("ABCD").isRotationOf("DAB") | ||
|
||
def foo[X](using x: X): X = x | ||
def bar[X](using x: X): X = x | ||
|
||
val x = foo // error | ||
val _ = bar // error |
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,15 @@ | ||
package example | ||
|
||
sealed trait Xa[T] | ||
sealed trait Mu[T] extends Xa[T] | ||
object Xa { | ||
implicit def convertMu[X[x] <: Xa[x], A, B](implicit t: X[A]): X[B] = t.asInstanceOf[X[B]] | ||
} | ||
object Mu { | ||
implicit def mu: Mu[Int] = new Mu[Int] {} | ||
} | ||
|
||
object Test extends App { | ||
def constrain(a: Mu[Long]): Unit = () | ||
constrain(Xa.convertMu) | ||
} |
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,17 @@ | ||
import scala.collection.SeqOps | ||
|
||
trait ComparingOps: | ||
extension[A, CC[B] <: SeqOps[B, CC, CC[B]]](ring: CC[A]) | ||
def isRotationOf(that: CC[A]): Boolean = true | ||
|
||
object RingSeq extends ComparingOps | ||
import RingSeq.* | ||
|
||
@main def Test = | ||
RingSeq.isRotationOf("DAB") // error | ||
"ABCD".isRotationOf("DAB") // error | ||
|
||
// workaround | ||
RingSeq.isRotationOf[Char, IndexedSeq]("DAB") | ||
RingSeq.isRotationOf(wrapString("DAB")) | ||
wrapString("ABCD").isRotationOf("DAB") |