-
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.
Fix pkg obj prefix of opaque tp ext meth
TypeOps.makePackageObjPrefixExplicit is a part of `accessibleType`, which is called on the result of findRef in typedIdent. But in `tryExtension` it's not. We could fix it in the usage of the results in `tryExtension`, but I thought perhaps we could fix it for all call sites, by handling it within findRef.
- Loading branch information
Showing
7 changed files
with
96 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
opaque type Pos = Double | ||
|
||
object Pos: | ||
extension (x: Pos) | ||
def mult1(y: Pos): Pos = x * y | ||
|
||
extension (x: Pos) | ||
def mult2(y: Pos): Pos = x * y | ||
|
||
class Test: | ||
def test(key: String, a: Pos, b: Pos): Unit = | ||
val tup1 = new Tuple1(Pos.mult1(a)(b)) | ||
val res1: Pos = tup1._1 | ||
|
||
val tup2 = new Tuple1(a.mult1(b)) | ||
val res2: Pos = tup2._1 | ||
|
||
val tup3 = new Tuple1(mult2(a)(b)) | ||
val res3: Pos = tup3._1 | ||
|
||
val tup4 = new Tuple1(a.mult2(b)) | ||
val res4: Pos = tup4._1 // was error: Found: (tup4._4 : Double) Required: Pos |
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,13 @@ | ||
opaque type Namespace = List[String] | ||
|
||
object Namespace: | ||
def apply(head: String): Namespace = List(head) | ||
|
||
extension (ns: Namespace) | ||
def appended(segment: String): Namespace = ns.appended(segment) | ||
|
||
object Main: | ||
def main(args: Array[String]): Unit = | ||
val a: Namespace = Namespace("a") | ||
.appended("B") | ||
.appended("c") // was error: Found: List[String] Required: Namespace |
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,13 @@ | ||
object Main: | ||
opaque type Namespace = List[String] | ||
|
||
object Namespace: | ||
def apply(head: String): Namespace = List(head) | ||
|
||
extension (ns: Namespace) | ||
def appended(segment: String): Namespace = ns.appended(segment) | ||
|
||
def main(args: Array[String]): Unit = | ||
val a: Namespace = Namespace("a") | ||
.appended("B") | ||
.appended("c") |
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,9 @@ | ||
package test | ||
|
||
type Foo = Unit | ||
val bar: Foo = () | ||
|
||
opaque type Opaque = Unit | ||
|
||
extension (foo: Foo) | ||
def go: Option[Opaque] = ??? |
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,13 @@ | ||
package test | ||
|
||
final case class Test(value: Opaque) | ||
|
||
def test: Test = | ||
bar.go match | ||
case Some(value) => Test(value) // was error: Found: (value : Unit) Required: test.Opaque | ||
case _ => ??? | ||
|
||
def test2: Test = | ||
go(bar) match | ||
case Some(value) => Test(value) | ||
case _ => ??? |
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,20 @@ | ||
opaque type PositiveNumber = Double | ||
|
||
object PositiveNumber: | ||
extension (x: PositiveNumber) | ||
def mult1(other: PositiveNumber): PositiveNumber = | ||
x * other | ||
|
||
extension (x: PositiveNumber) | ||
def mult2(other: PositiveNumber): PositiveNumber = | ||
x * other | ||
|
||
object Test: | ||
def multMap1[A](x: Map[A, PositiveNumber], num: PositiveNumber): Map[A, PositiveNumber] = x.map((key, value) => key -> value.mult1(num)).toMap | ||
|
||
def multMap2[A](x: Map[A, PositiveNumber], num: PositiveNumber): Map[A, PositiveNumber] = x.map((key, value) => key -> value.mult2(num)).toMap // was error | ||
// ^ | ||
// Cannot prove that (A, Double) <:< (A, V2). | ||
// | ||
// where: V2 is a type variable with constraint <: PositiveNumber | ||
def multMap2_2[A](x: Map[A, PositiveNumber], num: PositiveNumber): Map[A, PositiveNumber] = x.map((key, value) => key -> mult2(value)(num)).toMap |