Created
April 5, 2020 17:44
-
-
Save etorreborre/8f0a06392b8dbc1a13b7ad44bb4fb764 to your computer and use it in GitHub Desktop.
Bug with Dotty macros?
This file contains hidden or 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
case class FileName private(name: String) | |
/** | |
val fileName1: FileName = ToFileName("fileName1") | |
-- Error: /Users/etorreborre/projects/specs2/specs2-five/common/shared/src/test/scala/org/specs2/io/DirectoryPathSpec.scala:13:38 | |
[error] 13 | val fileName1: FileName = ToFileName("fileName1") | |
[error] | ^^^^^^^^^^^ | |
[error] | fileName1 is not a valid file name! It must not contain a / | |
*/ | |
object FileName { | |
def unsafe(s: String) = new FileName(s) | |
implicit inline def ToFileName(s: String): FileName = | |
${createFileName('{s})} | |
def fileNameFromString(s: String): Either[String, FileName] = | |
Right(FileName.unsafe(s)) | |
def createFileName(fileName: Expr[String])(using qctx: QuoteContext): Expr[FileName] = | |
fileName match { | |
case e@Const(s) => | |
'{fileNameFromString($e) match { | |
case Right(fn) => | |
fn | |
case Left(_) => | |
${qctx.throwError(s"$s is not a valid file name! It must not contain a /", fileName)} | |
}} | |
case _ => | |
qctx.throwError(s"$fileName is not a valid file name. It must be a literal string", fileName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment