From 545e5364a0d2361d6dc81e25677086196911b695 Mon Sep 17 00:00:00 2001 From: Pawel Sadlo Date: Fri, 6 Sep 2024 09:06:04 +0200 Subject: [PATCH] better naming, moving comments to right place --- os/src-2/Macros.scala | 8 +++++--- os/src-3/Macros.scala | 7 ++++--- os/src/Path.scala | 5 ++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/os/src-2/Macros.scala b/os/src-2/Macros.scala index d594945d..e9cf590d 100644 --- a/os/src-2/Macros.scala +++ b/os/src-2/Macros.scala @@ -6,13 +6,15 @@ import os.PathChunk.{SubPathChunk, segmentsFromString} import scala.language.experimental.macros import acyclic.skipped -trait PathChunkMacros extends ViewBoundImplicit { - implicit def validatedStringChunk(s: String): PathChunk = macro Macros.validatedStringChunkImpl +// StringPathChunkConversion is a fallback to non-macro String => PathChunk implicit conversion in case eta expansion is needed, this is required for ArrayPathChunk and SeqPathChunk +trait PathChunkMacros extends StringPathChunkConversion { + implicit def stringPathChunkValidated(s: String): PathChunk = + macro Macros.stringPathChunkValidatedImpl } object Macros { - def validatedStringChunkImpl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[SubPathChunk] = { + def stringPathChunkValidatedImpl(c: blackbox.Context)(s: c.Expr[String]): c.Expr[SubPathChunk] = { import c.universe._ s match { diff --git a/os/src-3/Macros.scala b/os/src-3/Macros.scala index 2f0e17e3..292dc41a 100644 --- a/os/src-3/Macros.scala +++ b/os/src-3/Macros.scala @@ -6,12 +6,13 @@ import os.PathChunk.{SubPathChunk, segmentsFromString} import scala.collection.immutable.IndexedSeq import scala.quoted.{Expr, Quotes} -trait PathChunkMacros extends ViewBoundImplicit{ - inline implicit def validatedStringChunk(s:String): PathChunk = ${validatedPathChunkImpl('s)} +// StringPathChunkConversion is a fallback to non-macro String => PathChunk implicit conversion in case eta expansion is needed, this is required for ArrayPathChunk and SeqPathChunk +trait PathChunkMacros extends StringPathChunkConversion{ + inline implicit def stringPathChunkValidated(s:String): PathChunk = ${stringPathChunkValidatedImpl('s)} } object Macros { - def validatedPathChunkImpl(s:Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = { + def stringPathChunkValidatedImpl(s:Expr[String])(using quotes: Quotes): Expr[SubPathChunk] = { import quotes.reflect.* s.asTerm match { diff --git a/os/src/Path.scala b/os/src/Path.scala index cbd76df7..9c9416fa 100644 --- a/os/src/Path.scala +++ b/os/src/Path.scala @@ -11,10 +11,9 @@ trait PathChunk { def segments: Seq[String] def ups: Int } -trait ViewBoundImplicit { +trait StringPathChunkConversion { - // fallback to non-macro String => PathChunk implicit conversion in case eta expansion is needed, this is required for ArrayPathChunk and SeqPathChunk - implicit def validatedStringFunction(s: String): PathChunk = + implicit def stringToPathChunk(s: String): PathChunk = new PathChunk.StringPathChunkInternal(s) }