new Foo{}
form. Java reflection it is :worried:
class Foo
def foo[N](implicit n : sourcecode.Name.Aux[N], r : Require[SubString[N, 3]=="foo", "variable name must begin with 'foo'"]) : Foo = new Foo
val foo1 = foo() //OK
val goo1 = foo() //Compile-time fail: variable name must begin with 'foo'
2.12.5
macro death - upgrading to 2.12.6 fixed it
@lihaoyi, consider the following:
abstract class Foo(implicit n : sourcecode.Name) {
def getName = n.value
}
val wrapper : Foo = {
println(new Foo{}.getName)
new Foo{}
}
println(wrapper.getName)
This will print
wrapper
wrapper
Is it possible to modify the macro so it would print:
$anon
wrapper
?
sourcecode
library, so my question is - is it valuable enough to have in a library? or should I try writing my own macro for it?
if (x.name.value.contains("$")) ...
anonfun$1, anonfun$23, anonfun$41
etc, and then using reflection to insatiate classes.Text
captures last expression in the block). It feel like something relatively easy but I cant really figure out how to approach this. I looked ad Text
macro implementation but its not helpful in this case.Tree
/Expr
.
def text[T](thunk: =>T) = macro xxx
and then rely on rangepos
to get relevant part of the file. But this a long shot as I have never done it before and rely only on stuff I heard , so I cant say if it can work
Pkg
and FileName
, remove .scala
from the end of the filename and then concatenate them...