forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A relaxation concerning exported type aliases
The rules for export forwarders are changed as follows. Previously, all export forwarders were declared `final`. Now, only term members are declared `final`. Type aliases left aside. This makes it possible to export the same type member into several traits and then mix these traits in the same class. `typeclass-aggregates.scala` shows why this is essential to be able to combine multiple givens with type members. The change does not lose safety since different type aliases would in any case lead to uninstantiatable classes.
- Loading branch information
Showing
6 changed files
with
77 additions
and
7 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
-- [E170] Type Error: tests/neg/i0248-inherit-refined.scala:8:18 ------------------------------------------------------- | ||
8 | class C extends Y // error | ||
| ^ | ||
| test.A & test.B is not a class type | ||
| | ||
| longer explanation available when compiling with `-explain` | ||
-- [E170] Type Error: tests/neg/i0248-inherit-refined.scala:10:18 ------------------------------------------------------ | ||
10 | class D extends Z // error | ||
| ^ | ||
| test.A | test.B is not a class type | ||
| | ||
| 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//> using options -source future -language:experimental.modularity | ||
trait Ord: | ||
type This | ||
extension (x: This) | ||
def compareTo(y: This): Int | ||
def < (y: This): Boolean = compareTo(y) < 0 | ||
def > (y: This): Boolean = compareTo(y) > 0 | ||
|
||
trait OrdProxy extends Ord: | ||
export Ord.this.* | ||
|
||
trait SemiGroup: | ||
type This | ||
extension (x: This) def combine(y: This): This | ||
|
||
trait SemiGroupProxy extends SemiGroup: | ||
export SemiGroup.this.* | ||
|
||
trait Monoid extends SemiGroup: | ||
def unit: This | ||
|
||
trait MonoidProxy extends Monoid: | ||
export Monoid.this.* | ||
|
||
def ordWithMonoid(ord: Ord, monoid: Monoid{ type This = ord.This }): Ord & Monoid = | ||
new ord.OrdProxy with monoid.MonoidProxy {} | ||
|
||
trait OrdWithMonoid extends Ord, Monoid | ||
|
||
def ordWithMonoid2(ord: Ord, monoid: Monoid{ type This = ord.This }) = //: OrdWithMonoid { type This = ord.This} = | ||
new OrdWithMonoid with ord.OrdProxy with monoid.MonoidProxy {} | ||
|
||
given intOrd: Ord { type This = Int } = ??? | ||
given intMonoid: Monoid { type This = Int } = ??? | ||
|
||
//given (using ord: Ord, monoid: Monoid{ type This = ord.This }): (Ord & Monoid { type This = ord.This}) = | ||
// ordWithMonoid2(ord, monoid) | ||
|
||
val x = summon[Ord & Monoid { type This = Int}] | ||
val y: Int = ??? : x.This | ||
|
||
// given [A, B](using ord: A is Ord, monoid: A is Monoid) => A is Ord & Monoid = | ||
// new ord.OrdProxy with monoid.MonoidProxy {} | ||
|
||
given [A](using ord: Ord { type This = A }, monoid: Monoid { type This = A}): (Ord & Monoid) { type This = A} = | ||
new ord.OrdProxy with monoid.MonoidProxy {} | ||
|