forked from scala/scala3
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow leading context parameters in extension methods
Fixes scala#9530
- Loading branch information
1 parent
90b56b5
commit 913386c
Showing
7 changed files
with
89 additions
and
12 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,8 @@ | ||
-- Error: tests/neg/rightassoc-extmethod.scala:1:23 -------------------------------------------------------------------- | ||
1 |extension (x: Int) def +: (using String): Int = x // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| right-associative extension method cannot start with using clause | ||
-- Error: tests/neg/rightassoc-extmethod.scala:2:23 -------------------------------------------------------------------- | ||
2 |extension (x: Int) def *: (y: Int, z: Int) = x // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| right-associative extension method must start with a single parameter |
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,3 @@ | ||
extension (x: Int) def +: (using String): Int = x // error | ||
extension (x: Int) def *: (y: Int, z: Int) = x // 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,35 @@ | ||
trait Scope: | ||
type Expr | ||
type Value | ||
def expr(x: String): Expr | ||
def value(e: Expr): Value | ||
def combine(e: Expr, str: String): Expr | ||
|
||
extension (using s: Scope)(expr: s.Expr) | ||
def show = expr.toString | ||
def eval = s.value(expr) | ||
def *: (str: String) = s.combine(expr, str) | ||
|
||
def f(using s: Scope)(x: s.Expr): (String, s.Value) = | ||
(x.show, x.eval) | ||
|
||
given scope: Scope with | ||
case class Expr(str: String) | ||
type Value = Int | ||
def expr(x: String) = Expr(x) | ||
def value(e: Expr) = e.str.toInt | ||
def combine(e: Expr, str: String) = Expr(e.str ++ str) | ||
|
||
@main def Test = | ||
val e = scope.Expr("123") | ||
val (s, v) = f(e) | ||
println(s) | ||
println(v) | ||
val ss = e.show | ||
println(ss) | ||
val vv = e.eval | ||
println(vv) | ||
val e2 = e *: "4" | ||
println(e2.show) | ||
println(e2.eval) | ||
|