Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9594 from smarter/and-syntax
Support writing `&` instead of `with` in types under `-Xsource:3`
- Loading branch information
Showing
5 changed files
with
77 additions
and
3 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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
and-future.scala:9: error: Cannot parse infix type combining `&` and `Map`, please use `Map` as the head of a regular type application. | ||
val b: Int Map X & Int Map Y = Map[Int, X & Y]() // error: unsupported | ||
^ | ||
and-future.scala:13: error: Cannot parse infix type combining `&` and `Map`, please use `Map` as the head of a regular type application. | ||
val c: (Int Map X) & (Int Map Y) = Map[Int, X & Y]() // error: unsupported | ||
^ | ||
2 errors |
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,14 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
|
||
trait X | ||
trait Y | ||
|
||
class Test { | ||
val a: Map[Int, X] & Map[Int, Y] = Map[Int, X & Y]() // ok | ||
val b: Int Map X & Int Map Y = Map[Int, X & Y]() // error: unsupported | ||
|
||
// This one is unambiguous but it's hard to check whether parens were present | ||
// from the parser output so we also emit an error there. | ||
val c: (Int Map X) & (Int Map Y) = Map[Int, X & Y]() // error: unsupported | ||
} |
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 @@ | ||
// scalac: -Xsource:3 | ||
// | ||
|
||
trait X | ||
trait Y | ||
|
||
class Test[A, B <: A & AnyRef] { | ||
def foo[T >: A & Null <: A & AnyRef & Any](x: T & ""): "" & T = x | ||
|
||
val a: X & Y & AnyRef = new X with Y {} | ||
val b: (X & Y) & AnyRef = new X with Y {} | ||
val c: X & (Y & AnyRef) = new X with Y {} | ||
|
||
val d: X & Y = c match { | ||
case xy: (X & Y) => xy | ||
} | ||
} |