diff --git a/community-build/community-projects/munit b/community-build/community-projects/munit index 3ce72dda2454..7e1c572b2fa9 160000 --- a/community-build/community-projects/munit +++ b/community-build/community-projects/munit @@ -1 +1 @@ -Subproject commit 3ce72dda2454d1a1cd8d1b150d3b9120cd541869 +Subproject commit 7e1c572b2fa9435e12dc582319cc1c09633983e0 diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index 4a6cb5fb2adb..1ba232a02a22 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit 4a6cb5fb2adb20644b4b1daebb933fa80434d877 +Subproject commit 1ba232a02a220e0989970b36342f6ad95f5cff01 diff --git a/community-build/community-projects/sourcecode b/community-build/community-projects/sourcecode index ee2aaad5c8f0..88b80f483f0c 160000 --- a/community-build/community-projects/sourcecode +++ b/community-build/community-projects/sourcecode @@ -1 +1 @@ -Subproject commit ee2aaad5c8f0a634276040e8a537c2c407e4d777 +Subproject commit 88b80f483f0c817addc097c90327cb423c254be1 diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 6ec0a4852077..8dc8e70dabfa 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 6ec0a485207791f81517571bb26d09370c9704c4 +Subproject commit 8dc8e70dabfa67417a0dfaf91a010c76dda842d4 diff --git a/community-build/community-projects/verify b/community-build/community-projects/verify index cd444ea0659a..95fb4082f072 160000 --- a/community-build/community-projects/verify +++ b/community-build/community-projects/verify @@ -1 +1 @@ -Subproject commit cd444ea0659a9680b49319efda1b00a8dcc09f88 +Subproject commit 95fb4082f0729208ff465d81a043f2e77baa900d diff --git a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala index 813423194136..5b4296fd5daa 100644 --- a/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala +++ b/compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala @@ -2556,26 +2556,27 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler def endLine: Int = self.endLine def startColumn: Int = self.startColumn def endColumn: Int = self.endColumn - def sourceCode: String = - new String(self.source.content(), self.start, self.end - self.start) + def sourceCode: Option[String] = + // TODO detect when we do not have a source and return None + Some(new String(self.source.content(), self.start, self.end - self.start)) end extension end PositionMethodsImpl type SourceFile = dotc.util.SourceFile - object SourceFile extends SourceFileModule + object SourceFile extends SourceFileModule { + def current: SourceFile = ctx.compilationUnit.source + } object SourceFileMethodsImpl extends SourceFileMethods: extension (self: SourceFile): def jpath: java.nio.file.Path = self.file.jpath - def content: String = new String(self.content()) + def content: Option[String] = + // TODO detect when we do not have a source and return None + Some(new String(self.content())) end extension end SourceFileMethodsImpl - object Source extends SourceModule: - def path: java.nio.file.Path = ctx.compilationUnit.source.file.jpath - end Source - object report extends reportModule: def error(msg: String): Unit = diff --git a/library/src/scala/quoted/Quotes.scala b/library/src/scala/quoted/Quotes.scala index f1108b48c055..8c8a324af7a8 100644 --- a/library/src/scala/quoted/Quotes.scala +++ b/library/src/scala/quoted/Quotes.scala @@ -4133,7 +4133,7 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => def endColumn: Int /** Source code within the position */ - def sourceCode: String + def sourceCode: Option[String] end extension } @@ -4145,7 +4145,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => val SourceFile: SourceFileModule /** Methods of the module object `val SourceFile` */ - trait SourceFileModule { this: SourceFile.type => } + trait SourceFileModule { this: SourceFile.type => + /** Returns the source file being compiled. The path is relative to the current working directory. */ + def current: SourceFile + } /** Makes extension methods on `SourceFile` available without any imports */ given SourceFileMethods: SourceFileMethods = SourceFileMethodsImpl @@ -4160,25 +4163,10 @@ trait Quotes { self: runtime.QuoteUnpickler & runtime.QuoteMatching => def jpath: java.nio.file.Path /** Content of this source file */ - def content: String + def content: Option[String] end extension } - /////////////// - // Source // - /////////////// - - /** Module object of `type Source` */ - val Source: SourceModule - - /** Methods of the module object `val Source` */ - trait SourceModule { this: Source.type => - - /** Returns the source file being compiled. The path is relative to the current working directory. */ - def path: java.nio.file.Path - - } - /////////////// // REPORTING // /////////////// diff --git a/tests/run-macros/reflect-sourceCode/Macro_1.scala b/tests/run-macros/reflect-sourceCode/Macro_1.scala index d9a48a13a143..8a9173ad01ad 100644 --- a/tests/run-macros/reflect-sourceCode/Macro_1.scala +++ b/tests/run-macros/reflect-sourceCode/Macro_1.scala @@ -6,6 +6,6 @@ object api { private def reflImpl[T](x: Expr[T])(implicit qctx: Quotes): Expr[String] = { import quotes.reflect._ - Expr(Term.of(x).pos.sourceCode) + Expr(Term.of(x).pos.sourceCode.get) } } diff --git a/tests/run-macros/tasty-getfile-implicit-by-name-fun-context/Macro_1.scala b/tests/run-macros/tasty-getfile-implicit-by-name-fun-context/Macro_1.scala index a5f6d9742b11..6fc28ac4403f 100644 --- a/tests/run-macros/tasty-getfile-implicit-by-name-fun-context/Macro_1.scala +++ b/tests/run-macros/tasty-getfile-implicit-by-name-fun-context/Macro_1.scala @@ -8,6 +8,7 @@ object SourceFiles { ${getThisFileImpl} def getThisFileImpl: Macro[String] = - Expr(quotes.reflect.Source.path.getFileName.toString) + val q = quotes // Quotes is ByName and hence not stable (q stabilizes it) + Expr(q.reflect.SourceFile.current.jpath.getFileName.toString) } diff --git a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala index 4411f3960f7a..eab7808ac0fb 100644 --- a/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala +++ b/tests/run-macros/tasty-getfile-implicit-fun-context/Macro_1.scala @@ -10,7 +10,7 @@ object SourceFiles { def getThisFileImpl: Macro[String] = { val qctx = tastyContext - Expr(qctx.reflect.Source.path.getFileName.toString) + Expr(qctx.reflect.SourceFile.current.jpath.getFileName.toString) } } diff --git a/tests/run-macros/tasty-getfile/Macro_1.scala b/tests/run-macros/tasty-getfile/Macro_1.scala index 275ee57ff410..5e9ccb58e1f0 100644 --- a/tests/run-macros/tasty-getfile/Macro_1.scala +++ b/tests/run-macros/tasty-getfile/Macro_1.scala @@ -7,6 +7,6 @@ object SourceFiles { ${getThisFileImpl} private def getThisFileImpl(using Quotes) : Expr[String] = - Expr(quotes.reflect.Source.path.getFileName.toString) + Expr(quotes.reflect.SourceFile.current.jpath.getFileName.toString) } diff --git a/tests/run-macros/tasty-original-source/Macros_1.scala b/tests/run-macros/tasty-original-source/Macros_1.scala index 9a37014a802a..71bbb6c2dd80 100644 --- a/tests/run-macros/tasty-original-source/Macros_1.scala +++ b/tests/run-macros/tasty-original-source/Macros_1.scala @@ -6,7 +6,7 @@ object Macros { private def impl(arg: Expr[Any])(using Quotes) : Expr[(String, Any)] = { import quotes.reflect._ - val source = Expr(Term.of(arg).underlyingArgument.pos.sourceCode.toString) + val source = Expr(Term.of(arg).underlyingArgument.pos.sourceCode.get.toString) '{Tuple2($source, $arg)} }