Skip to content

Commit

Permalink
+ Sketch first (dirty) draft - not working
Browse files Browse the repository at this point in the history
  • Loading branch information
stanch committed Jan 12, 2014
1 parent 0195efb commit 5e38e3b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.dslparadise.annotations

import scala.annotation.StaticAnnotation

class Implicit extends StaticAnnotation

class Import extends StaticAnnotation
19 changes: 17 additions & 2 deletions plugin/src/main/scala/org/dslparadise/typechecker/Typers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,23 @@ trait Typers {
import infer._

override def typedArgsForFormals(args: List[Tree], formals: List[Type], mode: Mode): List[Tree] = {
println("hello world")
super.typedArgsForFormals(args, formals, mode)
val Impl = typeOf[org.dslparadise.annotations.Implicit]
val Impo = typeOf[org.dslparadise.annotations.Import]
val desugared = (args zip formals) map {
case (tree, formal @ TypeRef(_, _, List(AnnotatedType(List(AnnotationInfo(Impl, _, _)), left, _), right)))
val tpe = typed(tree.duplicate).tpe
if (!(tpe <:< formal) || tpe.isError) {
val fixed = q"{ implicit u: $left$tree }"
val fixedTpe = typed(fixed).tpe
println(tree, fixed, fixedTpe)
fixed
} else {
tree
}
case (tree, tp) tree
}
println(s"desugared $args to $desugared")
super.typedArgsForFormals(desugared, formals, mode)
}
}
}
2 changes: 1 addition & 1 deletion project/build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object build extends Build {
base = file("sandbox")
) settings (
sharedSettings ++ usePluginSettings: _*
)
) dependsOn plugin

lazy val tests = Project(
id = "tests",
Expand Down
9 changes: 9 additions & 0 deletions sandbox/src/main/scala/Main.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import org.dslparadise.annotations._

object Main extends App {
def f(a: (Int @Implicit) Int) = a(8)

def g(implicit x: Int) = x + 3

f(8 + g)
}

0 comments on commit 5e38e3b

Please sign in to comment.