Skip to content

Commit 59932c5

Browse files
committed
Use new extension syntax in scala.compiletime
1 parent 7015c7f commit 59932c5

File tree

2 files changed

+21
-19
lines changed

2 files changed

+21
-19
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ class Definitions {
226226
@tu lazy val Compiletime_error : Symbol = CompiletimePackageObject.requiredMethod(nme.error)
227227
@tu lazy val Compiletime_constValue : Symbol = CompiletimePackageObject.requiredMethod("constValue")
228228
@tu lazy val Compiletime_constValueOpt: Symbol = CompiletimePackageObject.requiredMethod("constValueOpt")
229-
@tu lazy val Compiletime_code : Symbol = CompiletimePackageObject.requiredMethod("code")
229+
@tu lazy val Compiletime_code : Symbol = CompiletimePackageObject.requiredMethod("extension_code")
230230
@tu lazy val Compiletime_summonFrom : Symbol = CompiletimePackageObject.requiredMethod("summonFrom")
231231
@tu lazy val CompiletimeTestingPackageObject: Symbol = ctx.requiredModule("scala.compiletime.testing.package")
232232
@tu lazy val CompiletimeTesting_typeChecks: Symbol = CompiletimeTestingPackageObject.requiredMethod("typeChecks")

library/src/scala/compiletime/package.scala

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,24 +29,26 @@ package object compiletime {
2929
*/
3030
inline def error(inline msg: String): Nothing = ???
3131

32-
/** Returns the string representation of interpolated elaborated code:
33-
*
34-
* ```scala
35-
* inline def logged(p1: => Any) = {
36-
* val c = code"code: $p1"
37-
* val res = p1
38-
* (c, p1)
39-
* }
40-
* logged(identity("foo"))
41-
* // above is equivalent to:
42-
* // ("code: scala.Predef.identity("foo")", identity("foo"))
43-
* ```
44-
*
45-
* @note only by-name arguments will be displayed as "code".
46-
* Other values may display unintutively.
47-
*/
48-
transparent inline def (inline self: StringContext) code (inline args: Any*): String =
49-
${ dotty.internal.CompileTimeMacros.codeExpr('self, 'args) }
32+
extension (inline self: StringContext):
33+
/** Returns the string representation of interpolated elaborated code:
34+
*
35+
* ```scala
36+
* inline def logged(p1: => Any) = {
37+
* val c = code"code: $p1"
38+
* val res = p1
39+
* (c, p1)
40+
* }
41+
* logged(identity("foo"))
42+
* // above is equivalent to:
43+
* // ("code: scala.Predef.identity("foo")", identity("foo"))
44+
* ```
45+
*
46+
* @note only by-name arguments will be displayed as "code".
47+
* Other values may display unintutively.
48+
*/
49+
transparent inline def code (inline args: Any*): String =
50+
${ dotty.internal.CompileTimeMacros.codeExpr('self, 'args) }
51+
end extension
5052

5153
/** Same as `constValue` but returns a `None` if a constant value
5254
* cannot be constructed from the provided type. Otherwise returns

0 commit comments

Comments
 (0)