-
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.
Disallow use of
PolyFunction
in user code
The `PolyFunction` trait should only be used for compiler generated encoded lambdas. Any other use case that was allowed before was accidental. In the future, we might consider supporting these if there is a good use case. This would probably require a SIP.
- Loading branch information
1 parent
1b4b390
commit 4ed7893
Showing
10 changed files
with
57 additions
and
83 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 |
---|---|---|
@@ -1,32 +1,36 @@ | ||
-- Error: tests/neg/i10075.scala:8:24 ---------------------------------------------------------------------------------- | ||
8 |trait PolyTrait extends PolyFunction // error | ||
-- Error: tests/neg/i10075.scala:9:24 ---------------------------------------------------------------------------------- | ||
9 |trait PolyTrait extends PolyFunction // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
-- Error: tests/neg/i10075.scala:10:24 --------------------------------------------------------------------------------- | ||
10 |class PolyClass extends PolyTrait { // error | ||
| ^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
-- Error: tests/neg/i10075.scala:14:26 --------------------------------------------------------------------------------- | ||
14 |object PolyObject extends PolyFunction // error | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:11:24 --------------------------------------------------------------------------------- | ||
11 |class PolyClass extends PolyFunction { // error | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:15:26 --------------------------------------------------------------------------------- | ||
15 |object PolyObject extends PolyFunction // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:2:14 ---------------------------------------------------------------------------------- | ||
2 |val foo = new PolyFunction { } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
-- Error: tests/neg/i10075.scala:3:14 ---------------------------------------------------------------------------------- | ||
3 |val bar = new PolyFunction { def bar = 23 } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:3:21 ---------------------------------------------------------------------------------- | ||
3 |val foo2 = new scala.PolyFunction { } // error | ||
| ^^^^^^^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:4:14 ---------------------------------------------------------------------------------- | ||
4 |val baz = new PolyFunction { def apply = 23 } // error | ||
4 |val bar = new PolyFunction { def bar = 23 } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:5:14 ---------------------------------------------------------------------------------- | ||
5 |val qux = new PolyFunction { def apply[T] = 47 } // error | ||
5 |val baz = new PolyFunction { def apply = 23 } // error | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:6:14 ---------------------------------------------------------------------------------- | ||
6 |val qux = new PolyFunction { def apply[T] = 47 } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
-- Error: tests/neg/i10075.scala:6:15 ---------------------------------------------------------------------------------- | ||
6 |val quxx = new PolyFunction { def apply[T](x: T): T = x } // error | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i10075.scala:7:15 ---------------------------------------------------------------------------------- | ||
7 |val quxx = new PolyFunction { def apply[T](x: T): T = x } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |
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,4 +1,4 @@ | ||
def test = polyFun(1) | ||
|
||
def polyFun: PolyFunction { def apply(x: Int): Int } = | ||
def polyFun: PolyFunction { def apply(x: Int): Int } = // error | ||
new PolyFunction { def apply(x: Int): Int = x + 1 } // 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,8 +1,8 @@ | ||
-- Error: tests/neg/i18302b.scala:3:32 --------------------------------------------------------------------------------- | ||
-- Error: tests/neg/i18302b.scala:3:13 --------------------------------------------------------------------------------- | ||
3 |def polyFun: PolyFunction { def apply(x: Int)(y: Int): Int } = // error | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed. | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302b.scala:4:6 ---------------------------------------------------------------------------------- | ||
4 | new PolyFunction: // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |
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,8 +1,8 @@ | ||
-- Error: tests/neg/i18302c.scala:4:32 --------------------------------------------------------------------------------- | ||
-- Error: tests/neg/i18302c.scala:4:13 --------------------------------------------------------------------------------- | ||
4 |def polyFun: PolyFunction { def foo(x: Int): Int } = // error | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| PolyFunction only supports apply method refinements | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302c.scala:5:6 ---------------------------------------------------------------------------------- | ||
5 | new PolyFunction { def foo(x: Int): Int = x + 1 } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |
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,8 +1,8 @@ | ||
-- Error: tests/neg/i18302d.scala:1:32 --------------------------------------------------------------------------------- | ||
-- Error: tests/neg/i18302d.scala:1:13 --------------------------------------------------------------------------------- | ||
1 |def polyFun: PolyFunction { def apply: Int } = // error | ||
| ^^^^^^^^^^^^^^ | ||
|Implementation restriction: PolyFunction apply must have exactly one parameter list and optionally type arguments. No by-name nor varags are allowed. | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302d.scala:2:6 ---------------------------------------------------------------------------------- | ||
2 | new PolyFunction { def apply: Int = 1 } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |
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,12 +1,12 @@ | ||
-- Error: tests/neg/i18302e.scala:1:13 --------------------------------------------------------------------------------- | ||
1 |def polyFun: PolyFunction { } = // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302e.scala:2:6 ---------------------------------------------------------------------------------- | ||
2 | new PolyFunction { } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302e.scala:4:15 --------------------------------------------------------------------------------- | ||
4 |def polyFun(f: PolyFunction { }) = () // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
| ^^^^^^^^^^^^ | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |
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,20 +1,20 @@ | ||
-- Error: tests/neg/i18302f.scala:1:13 --------------------------------------------------------------------------------- | ||
1 |def polyFun: PolyFunction = // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302f.scala:2:6 ---------------------------------------------------------------------------------- | ||
2 | new PolyFunction { } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302f.scala:4:16 --------------------------------------------------------------------------------- | ||
4 |def polyFun2(a: PolyFunction) = () // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302f.scala:6:14 --------------------------------------------------------------------------------- | ||
6 |val polyFun3: PolyFunction = // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. | ||
-- Error: tests/neg/i18302f.scala:7:6 ---------------------------------------------------------------------------------- | ||
7 | new PolyFunction { } // error | ||
| ^^^^^^^^^^^^ | ||
| `PolyFunction` marker trait is reserved for compiler generated refinements | ||
| Direct use of `PolyFunction` is not allowed. Use lambda instead. |