-
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.
Allow class parents to be refined types.
Refinements of a class parent are added as synthetic members to the inheriting class.
- Loading branch information
Showing
12 changed files
with
200 additions
and
86 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
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,10 +1,12 @@ | ||
//> using options -source future -language:experimental.modularity | ||
|
||
object test { | ||
class A { type T } | ||
type X = A { type T = Int } | ||
class B extends X // error | ||
class B extends X // was error, now OK | ||
type Y = A & B | ||
class C extends Y // error | ||
type Z = A | B | ||
class D extends Z // error | ||
abstract class E extends ({ val x: Int }) // error | ||
abstract class E extends ({ val x: Int }) // was error, now OK | ||
} |
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,7 @@ | ||
-- [E164] Declaration Error: tests/neg/parent-refinement-access.scala:6:6 ---------------------------------------------- | ||
6 |trait Year2(private[Year2] val value: Int) extends (Gen { val x: Int }) // error | ||
| ^ | ||
| error overriding value x in trait Year2 of type Int; | ||
| value x in trait Gen of type Any has weaker access privileges; it should be public | ||
| (Note that value x in trait Year2 of type Int is abstract, | ||
| and is therefore overridden by concrete value x in trait Gen of type Any) |
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,6 @@ | ||
//> using options -source future -language:experimental.modularity | ||
|
||
trait Gen: | ||
private[Gen] val x: Any = () | ||
|
||
trait Year2(private[Year2] val value: Int) extends (Gen { val x: Int }) // 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 |
---|---|---|
@@ -1,4 +1,25 @@ | ||
-- Error: tests/neg/parent-refinement.scala:5:2 ------------------------------------------------------------------------ | ||
5 | with Ordered[Year] { // error | ||
| ^^^^ | ||
| end of toplevel definition expected but 'with' found | ||
-- Error: tests/neg/parent-refinement.scala:11:6 ----------------------------------------------------------------------- | ||
11 |class Bar extends IdOf[Int], (X { type Value = String }) // error | ||
| ^^^ | ||
|class Bar cannot be instantiated since it has a member Value with possibly conflicting bounds Int | String <: ... <: Int & String | ||
-- [E007] Type Mismatch Error: tests/neg/parent-refinement.scala:15:17 ------------------------------------------------- | ||
15 | val x: Value = 0 // error | ||
| ^ | ||
| Found: (0 : Int) | ||
| Required: Baz.this.Value | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/parent-refinement.scala:21:6 -------------------------------------------------- | ||
21 | foo(2) // error | ||
| ^ | ||
| Found: (2 : Int) | ||
| Required: Boolean | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E007] Type Mismatch Error: tests/neg/parent-refinement.scala:17:22 ------------------------------------------------- | ||
17 |val x: IdOf[Int] = Baz() // error | ||
| ^^^^^ | ||
| Found: Baz | ||
| Required: IdOf[Int] | ||
| | ||
| longer explanation available when compiling with `-explain` |
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,7 +1,21 @@ | ||
//> using options -source future -language:experimental.modularity | ||
|
||
trait Id { type Value } | ||
trait X { type Value } | ||
type IdOf[T] = Id { type Value = T } | ||
|
||
case class Year(value: Int) extends AnyVal | ||
with Id { type Value = Int } | ||
with Ordered[Year] { // error | ||
with (Id { type Value = Int }) | ||
with Ordered[Year] | ||
|
||
class Bar extends IdOf[Int], (X { type Value = String }) // error | ||
|
||
class Baz extends IdOf[Int]: | ||
type Value = String | ||
val x: Value = 0 // error | ||
|
||
val x: IdOf[Int] = Baz() // error | ||
|
||
} | ||
object Clash extends ({ def foo(x: Int): Int }): | ||
def foo(x: Boolean): Int = 1 | ||
foo(2) // 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,48 @@ | ||
//> using options -source future -language:experimental.modularity | ||
|
||
class A | ||
class B extends A | ||
class C extends B | ||
|
||
trait Id { type Value } | ||
type IdOf[T] = Id { type Value = T } | ||
trait X { type Value } | ||
|
||
case class Year(value: Int) extends IdOf[Int]: | ||
val x: Value = 2 | ||
|
||
type Between[Lo, Hi] = X { type Value >: Lo <: Hi } | ||
|
||
class Foo() extends IdOf[B], Between[C, A]: | ||
val x: Value = B() | ||
|
||
trait Bar extends IdOf[Int], (X { type Value = String }) | ||
|
||
class Baz extends IdOf[Int]: | ||
type Value = String | ||
val x: Value = "" | ||
|
||
trait Gen: | ||
type T | ||
val x: T | ||
|
||
type IntInst = Gen: | ||
type T = Int | ||
val x: 0 | ||
|
||
trait IntInstTrait extends IntInst | ||
|
||
abstract class IntInstClass extends IntInstTrait, IntInst | ||
|
||
object obj1 extends IntInstTrait: | ||
val x = 0 | ||
|
||
object obj2 extends IntInstClass: | ||
val x = 0 | ||
|
||
def main = | ||
val x: obj1.T = 2 - obj2.x | ||
val y: obj2.T = 2 - obj1.x | ||
|
||
|
||
|
Oops, something went wrong.