-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #132 from soronpo/getarg_mods
Ovehauling the GetArg functionality
- Loading branch information
Showing
11 changed files
with
199 additions
and
166 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package singleton.ops.impl | ||
|
||
|
||
//This is just for testing the GetArg workaround a problem a string interpolator arguments are applied | ||
protected[singleton] object InterpolatorTest { | ||
trait Bar | ||
trait Tag[W] extends HasOut { | ||
type Out = W | ||
} | ||
type XBar[W] = Bar with Tag[W] | ||
|
||
final implicit class InterpolatorSyntax(val sc: StringContext) { | ||
def bar(args: Bar*)(implicit interpolator : Interpolator[Bar]) : interpolator.Out = interpolator.value | ||
} | ||
trait Interpolator[T] extends HasOut { | ||
type Out <: T | ||
val value : Out | ||
} | ||
|
||
object Interpolator { | ||
type Aux[T, Out0 <: T] = Interpolator[T]{type Out = Out0} | ||
implicit def ev[W] : Interpolator.Aux[Bar, XBar[W]] = macro Macro.interpolator | ||
} | ||
|
||
protected object Macro { | ||
object whitebox { type Context = scala.reflect.macros.whitebox.Context } | ||
def interpolator(c: whitebox.Context) : c.Tree = { | ||
import c.universe._ | ||
val widthTpe = c.internal.constantType(Constant(5)) | ||
|
||
q""" | ||
new singleton.ops.impl.InterpolatorTest.Interpolator[singleton.ops.impl.InterpolatorTest.Bar] { | ||
type Out = singleton.ops.impl.InterpolatorTest.XBar[$widthTpe] | ||
val value : Out = new singleton.ops.impl.InterpolatorTest.Bar{}.asInstanceOf[singleton.ops.impl.InterpolatorTest.XBar[$widthTpe]] | ||
} | ||
""" | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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