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.
Check user defined PolyFunction refinements
`PolyFunction` must be refined with an `apply` method that has a single parameter list with no by-name nor varargs parameters. It may optionally have type parameters. Some of these restrictions could be lifted later, but for now these features are not properly handled by the compiler. Fixes scala#8299 Fixes scala#18302
- Loading branch information
1 parent
a37dac6
commit e5ca0c4
Showing
17 changed files
with
112 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-- Error: tests/neg/i18302b.scala:3:32 --------------------------------------------------------------------------------- | ||
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. |
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,5 @@ | ||
def test = polyFun(1)(2) | ||
|
||
def polyFun: PolyFunction { def apply(x: Int)(y: Int): Int } = // error | ||
new PolyFunction: | ||
def apply(x: Int)(y: Int): Int = x + y |
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,4 @@ | ||
-- Error: tests/neg/i18302c.scala:4:32 --------------------------------------------------------------------------------- | ||
4 |def polyFun: PolyFunction { def foo(x: Int): Int } = // error | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
| PolyFunction only supports apply method refinements |
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,5 @@ | ||
import scala.reflect.Selectable.reflectiveSelectable | ||
|
||
def test = polyFun.foo(1) | ||
def polyFun: PolyFunction { def foo(x: Int): Int } = // error | ||
new PolyFunction { def foo(x: Int): Int = x + 1 } |
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,4 @@ | ||
-- Error: tests/neg/i18302d.scala:1:32 --------------------------------------------------------------------------------- | ||
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. |
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,2 @@ | ||
def polyFun: PolyFunction { def apply: Int } = // error | ||
new PolyFunction { def apply: Int = 1 } |
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/i18302e.scala:1:13 --------------------------------------------------------------------------------- | ||
1 |def polyFun: PolyFunction { } = // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
-- Error: tests/neg/i18302e.scala:4:15 --------------------------------------------------------------------------------- | ||
4 |def polyFun(f: PolyFunction { }) = () // error | ||
| ^^^^^^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method |
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,4 @@ | ||
def polyFun: PolyFunction { } = // error | ||
new PolyFunction { } | ||
|
||
def polyFun(f: PolyFunction { }) = () // 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,12 @@ | ||
-- Error: tests/neg/i18302f.scala:1:13 --------------------------------------------------------------------------------- | ||
1 |def polyFun: PolyFunction = // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
-- Error: tests/neg/i18302f.scala:4:16 --------------------------------------------------------------------------------- | ||
4 |def polyFun2(a: PolyFunction) = () // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method | ||
-- Error: tests/neg/i18302f.scala:6:14 --------------------------------------------------------------------------------- | ||
6 |val polyFun3: PolyFunction = // error | ||
| ^^^^^^^^^^^^ | ||
| PolyFunction subtypes must refine the apply method |
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 @@ | ||
def polyFun: PolyFunction = // error | ||
new PolyFunction { } | ||
|
||
def polyFun2(a: PolyFunction) = () // error | ||
|
||
val polyFun3: PolyFunction = // error | ||
new PolyFunction { } |
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 @@ | ||
def polyFun1: Option[PolyFunction] = ??? // error | ||
def polyFun2: PolyFunction & Any = ??? // error | ||
def polyFun3: Any & PolyFunction = ??? // error | ||
def polyFun4: PolyFunction | Any = ??? // error | ||
def polyFun5: Any | PolyFunction = ??? // error | ||
def polyFun6(a: Any | PolyFunction) = ??? // 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,5 @@ | ||
def polyFunByName: PolyFunction { def apply(thunk: => Int): Int } = // error | ||
new PolyFunction { def apply(thunk: => Int): Int = 1 } | ||
|
||
def polyFunVarArgs: PolyFunction { def apply(args: Int*): Int } = // error | ||
new PolyFunction { def apply(thunk: Int*): Int = 1 } |
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 @@ | ||
package example | ||
|
||
object Main { | ||
def main(a: Array[String]): Unit = { | ||
val p: PolyFunction = // error: PolyFunction subtypes must refine the apply method | ||
[A] => (xs: List[A]) => xs.headOption | ||
} | ||
} |
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,4 @@ | ||
def test = polyFun(1) | ||
|
||
def polyFun: PolyFunction { def apply(x: Int): Int } = | ||
new PolyFunction { def apply(x: Int): Int = x + 1 } |