-
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.
SIP 61 - add errors when unrolling apply, copy and fromProduct
Also standardise error messages as Declaration Errors
- Loading branch information
1 parent
b1c2ec0
commit a6b757c
Showing
10 changed files
with
108 additions
and
43 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 |
---|---|---|
@@ -1,8 +1,8 @@ | ||
-- Error: tests/neg/unroll-abstractMethod.scala:6:6 -------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-abstractMethod.scala:6:41 ------------------------------------------------ | ||
6 | def foo(s: String, n: Int = 1, @unroll b: Boolean = true): String // error | ||
| ^ | ||
| Unrolled method must be final and concrete | ||
-- Error: tests/neg/unroll-abstractMethod.scala:10:6 ------------------------------------------------------------------- | ||
| ^ | ||
| Can not unroll parameters of method foo: it must not be abstract | ||
-- [E202] Declaration Error: tests/neg/unroll-abstractMethod.scala:10:41 ----------------------------------------------- | ||
10 | def foo(s: String, n: Int = 1, @unroll b: Boolean = true): String // error | ||
| ^ | ||
| Unrolled method must be final and concrete | ||
| ^ | ||
| Can not unroll parameters of method foo: it must not be abstract |
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 @@ | ||
-- [E202] Declaration Error: tests/neg/unroll-duped.scala:11:45 -------------------------------------------------------- | ||
11 | final def copy(s: String = this.s, @unroll y: Boolean = this.y): UnrolledCase = // error | ||
| ^ | ||
| Can not unroll parameters of method copy of a case class: please annotate the class constructor instead | ||
-- [E202] Declaration Error: tests/neg/unroll-duped.scala:18:12 -------------------------------------------------------- | ||
18 | @unroll y: Boolean = true // error | ||
| ^ | ||
|Can not unroll parameters of method apply of a case class companion object: please annotate the class constructor instead | ||
-- [E202] Declaration Error: tests/neg/unroll-duped.scala:22:26 -------------------------------------------------------- | ||
22 | def fromProduct(@unroll p: Product = EmptyTuple): UnrolledCase = { // error | ||
| ^ | ||
|Can not unroll parameters of method fromProduct of a case class companion object: please annotate the class constructor 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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//> using options -experimental | ||
|
||
import scala.annotation.unroll | ||
|
||
case class UnrolledCase( | ||
s: String, | ||
y: Boolean = true, | ||
) { | ||
def foo: String = s + y | ||
|
||
final def copy(s: String = this.s, @unroll y: Boolean = this.y): UnrolledCase = // error | ||
new UnrolledCase(s, y) | ||
} | ||
|
||
object UnrolledCase { | ||
def apply( | ||
s: String, | ||
@unroll y: Boolean = true // error | ||
): UnrolledCase = | ||
new UnrolledCase(s, y) | ||
|
||
def fromProduct(@unroll p: Product = EmptyTuple): UnrolledCase = { // error | ||
val s = p.productElement(0).asInstanceOf[String] | ||
val y = p.productElement(1).asInstanceOf[Boolean] | ||
UnrolledCase(s, 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 |
---|---|---|
@@ -1,36 +1,36 @@ | ||
-- Error: tests/neg/unroll-illegal.scala:6:6 --------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:6:6 -------------------------------------------------------- | ||
6 |class UnrollClass // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:9:6 --------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:9:6 -------------------------------------------------------- | ||
9 |trait UnrollTrait // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:12:7 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:12:7 ------------------------------------------------------- | ||
12 |object UnrollObject // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:18:5 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:18:5 ------------------------------------------------------- | ||
18 |enum UnrollEnum { case X } // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:21:25 ------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:21:25 ------------------------------------------------------ | ||
21 | val annotExpr: Int = 23: @unroll // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:22:19 ------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:22:19 ------------------------------------------------------ | ||
22 | type annotType = Int @unroll // error | ||
| ^^^^^^^^^^^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:25:6 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:25:6 ------------------------------------------------------- | ||
25 | val unrollVal: Int = 23 // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:28:6 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:28:6 ------------------------------------------------------- | ||
28 | def unrollDef: Int = 23 // error | ||
| ^ | ||
| @unroll is only allowed on a method parameter | ||
-- Error: tests/neg/unroll-illegal.scala:15:5 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal.scala:15:5 ------------------------------------------------------- | ||
15 |type UnrollType = Int // error | ||
| ^ | ||
| @unroll is only allowed on a method 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 |
---|---|---|
@@ -1,12 +1,12 @@ | ||
-- Error: tests/neg/unroll-illegal3.scala:7:8 -------------------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal3.scala:7:31 ------------------------------------------------------ | ||
7 | def foo(s: String, @unroll y: Boolean) = s + y // error | ||
| ^ | ||
| Unrolled method foo must be final | ||
-- Error: tests/neg/unroll-illegal3.scala:12:6 ------------------------------------------------------------------------- | ||
| ^ | ||
| Can not unroll parameters of method foo: it is not final | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal3.scala:12:29 ----------------------------------------------------- | ||
12 | def foo(s: String, @unroll y: Boolean) = s + y // error | ||
| ^ | ||
| Unrolled method foo must be final | ||
-- Error: tests/neg/unroll-illegal3.scala:16:6 ------------------------------------------------------------------------- | ||
| ^ | ||
| Can not unroll parameters of method foo: it is not final | ||
-- [E202] Declaration Error: tests/neg/unroll-illegal3.scala:16:29 ----------------------------------------------------- | ||
16 | def foo(s: String, @unroll y: Boolean): String // error | ||
| ^ | ||
| Unrolled method must be final and concrete | ||
| ^ | ||
| Can not unroll parameters of method foo: it must not be abstract |
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 @@ | ||
-- Error: tests/neg/unroll-traitConstructor.scala:5:12 ----------------------------------------------------------------- | ||
-- [E202] Declaration Error: tests/neg/unroll-traitConstructor.scala:5:32 ---------------------------------------------- | ||
5 |trait Unroll(a: String, @unroll b: Boolean = true): // error | ||
| ^ | ||
| implementation restriction: Unrolled method cannot be a trait constructor | ||
| ^ | ||
| implementation restriction: Can not unroll parameters of a trait constructor |