Skip to content

Commit cc8c77b

Browse files
Implement API for errors
Co-Authored-By: Jamie Thompson <[email protected]>
1 parent bb96612 commit cc8c77b

File tree

3 files changed

+35
-2
lines changed

3 files changed

+35
-2
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package scala.compiletime.testing
2+
3+
/** Represents a compile-time error.
4+
*
5+
* @see scala.compiletime.testing.typeCheckErrors
6+
*
7+
* IMPORTANT: No stability guarantees are provided on the format of these
8+
* errors. This means the format and the API may change from
9+
* version to version. This API is to be used for testing purposes
10+
* only.
11+
*/
12+
final case class Error(message: String, lineContent: String, column: Int, kind: ErrorKind)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package scala.compiletime.testing
2+
3+
/** An error can be either a parse-time or a typecheck-time */
4+
sealed trait ErrorKind // TODO make this enum, so far not doable because ScalaJS compilation fails on it
5+
object ErrorKind
6+
case object Parser extends ErrorKind
7+
case object Typer extends ErrorKind

library/src/scala/compiletime/testing/package.scala

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package scala.compiletime
22

3-
import scala.quoted._
4-
53
package object testing {
64

75
/** Whether the code type checks in the current context?
@@ -15,4 +13,20 @@ package object testing {
1513
inline def typeChecks(inline code: String): Boolean =
1614
error("`typeChecks` was not checked by the compiler")
1715

16+
/** Whether the code type checks in the current context? If not,
17+
* returns a list of errors encountered on compilation.
18+
* IMPORTANT: No stability guarantees are provided on the format of these
19+
* errors. This means the format and the API may change from
20+
* version to version. This API is to be used for testing purposes
21+
* only.
22+
*
23+
* @param code The code to be type checked
24+
*
25+
* @return a list of errors encountered during parsing and typechecking.
26+
*
27+
* The code should be a sequence of expressions or statements that may appear in a block.
28+
*/
29+
inline def typeCheckErrors(inline code: String): List[Error] =
30+
error("`typeCheckErrors` was not checked by the compiler")
31+
1832
}

0 commit comments

Comments
 (0)