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
14:58 ~/Projects/211x/sandbox (2.11.x)$ cat Macros.scala | |
import scala.reflect.macros.whitebox._ | |
import scala.language.experimental.macros | |
object Macros { | |
def macroImpl[T: c.WeakTypeTag](c: Context) = { | |
import c.universe._ | |
val tpe = weakTypeTag[T].tpe | |
implicit class RichType(tpe: Type) { | |
def pre: Type = tpe match { |
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
object Test extends App { | |
trait Term | |
class If extends Term | |
trait AllowedTransformation[I, O] | |
implicit object term2Term extends AllowedTransformation[Term, Term] | |
class Foo[T] { | |
def filter[U <: T : scala.reflect.ClassTag](f: PartialFunction[U, Boolean]): Foo[U] = { | |
println(scala.reflect.classTag[U]) |
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
import scala.reflect.macros.whitebox._ | |
import scala.language.experimental.macros | |
object Macros { | |
def impl(c: Context)(fn: c.Tree) = { | |
import c.universe._ | |
val Typed(Block(List(ClassDef(_, _, _, Template(_, _, stats))), _), _) = fn | |
val List(_, DefDef(_, TermName("applyOrElse"), _, _, _, Match(_, clauses :+ _)), _) = stats | |
val pfs = clauses.map(clause => { | |
object betterUntypecheck extends Transformer { |
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
diff --git a/src/compiler/scala/tools/nsc/typechecker/Macros.scala b/src/compiler/scala/tools/nsc/typechecker/Macros.scala | |
index 10aefae20b..1d09551244 100644 | |
--- a/src/compiler/scala/tools/nsc/typechecker/Macros.scala | |
+++ b/src/compiler/scala/tools/nsc/typechecker/Macros.scala | |
@@ -471,7 +471,7 @@ trait Macros extends MacroRuntimes with Traces with Helpers { | |
if (prefix == EmptyTree) macroDef.owner.tpe else prefix.tpe, | |
macroDef.owner) | |
} else | |
- targ.tpe | |
+ binding.targs(paramPos).tpe |
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
14:29 ~/Projects/scalahost/sandbox (master)$ cat Test.scala | |
package test | |
/** scaladoc for bar */ | |
class Bar | |
/** | |
* Scaladoc for Foo class | |
*/ | |
class Foo extends Bar { |
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
13:01 ~/Projects/scalahost/sandbox (master)$ s -Dconvert.debug | |
======= SCALA.REFLECT TREE ======= | |
package test { | |
class Bar extends scala.AnyRef { | |
def <init>(): test.Bar = { | |
Bar.super.<init>(); | |
() | |
} | |
}; | |
class Foo extends Bar { |
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
val build = SbtBuild("/path/to/project/root") | |
val project = build.projects("some-project-name") | |
project.compile() | |
println(project.fullClasspath) |
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
import scala.tools.nsc.reporters._ | |
import scala.tools.nsc.Settings | |
import reflect.runtime.Mirror.ToolBox | |
object Test extends App { | |
// todo. compose the tree, equivalent to t5230, by hand | |
import scala.reflect.mirror._ | |
import scala.reflect.api._ | |
import scala.reflect.api.Modifier._ |
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
Func<String, String> x = name => { | |
var buf = new StringBuilder(); | |
for (var i = 0; i < name.Length; ++i) { | |
var prev = i == 0 ? '\0' : name[i - 1]; | |
var curr = name[i]; | |
var next = i == name.Length - 1 ? '\0' : name[i + 1]; | |
if (Char.IsLower(prev) && Char.IsUpper(curr) && !Char.IsUpper(next)) { | |
buf.Append("-"); | |
buf.Append(Char.ToLower(curr)); | |
} else { |
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
error: recursive method factorial needs result type | |
Exception in thread "main" java.lang.Error: reflective compilation has failed | |
at scala.reflect.runtime.ToolBoxes$ToolBox$ToolBoxGlobal.runExpr(ToolBoxes.scala:95) | |
at scala.reflect.runtime.ToolBoxes$ToolBox.runExpr(ToolBoxes.scala:168) | |
at scala.reflect.runtime.ToolBoxes$ToolBox.runExpr(ToolBoxes.scala:171) | |
at Test$delayedInit$body.apply(t5274_0.scala:16) | |
at scala.Function0$class.apply$mcV$sp(Function0.scala:34) | |
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12) | |
at scala.App$$anonfun$main$1.apply(App.scala:61) | |
at scala.App$$anonfun$main$1.apply(App.scala:61) |