forked from scala/scala
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
blackbox restriction #3: can't affect implicit search
When an application of a blackbox macro is used as an implicit candidate, no expansion is performed until the macro is selected as the result of the implicit search. This makes it impossible to dynamically calculate availability of implicit macros.
- Loading branch information
Showing
14 changed files
with
125 additions
and
64 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
Test_2.scala:2: error: I don't like classes that contain integers | ||
println(implicitly[Foo[C1]]) | ||
^ | ||
one error found |
25 changes: 25 additions & 0 deletions
25
test/files/neg/macro-blackbox-dynamic-materialization/Macros_1.scala
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,25 @@ | ||
import scala.reflect.macros.BlackboxContext | ||
import scala.language.experimental.macros | ||
|
||
trait Foo[T] | ||
|
||
class C1(val x: Int) | ||
class C2(val x: String) | ||
|
||
trait LowPriority { | ||
implicit def lessSpecific[T]: Foo[T] = null | ||
} | ||
|
||
object Foo extends LowPriority { | ||
implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] | ||
} | ||
|
||
object Macros { | ||
def impl[T: c.WeakTypeTag](c: BlackboxContext) = { | ||
import c.universe._ | ||
val tpe = weakTypeOf[T] | ||
if (tpe.members.exists(_.typeSignature =:= typeOf[Int])) | ||
c.abort(c.enclosingPosition, "I don't like classes that contain integers") | ||
q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/files/neg/macro-blackbox-dynamic-materialization/Test_2.scala
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,4 @@ | ||
object Test extends App { | ||
println(implicitly[Foo[C1]]) | ||
println(implicitly[Foo[C2]]) | ||
} |
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 |
---|---|---|
@@ -1,12 +1,8 @@ | ||
Test_2.scala:7: Iso.materializeIso is not a valid implicit value for Iso[Test.Foo,L] because: | ||
hasMatchingSymbol reported error: type mismatch; | ||
Test_2.scala:7: error: type mismatch; | ||
found : Iso[Test.Foo,(Int, String, Boolean)] | ||
required: Iso[Test.Foo,Nothing] | ||
Note: (Int, String, Boolean) >: Nothing, but trait Iso is invariant in type U. | ||
You may wish to define U as -U instead. (SLS 4.5) | ||
val equiv = foo(Foo(23, "foo", true)) | ||
^ | ||
Test_2.scala:7: error: could not find implicit value for parameter iso: Iso[Test.Foo,L] | ||
val equiv = foo(Foo(23, "foo", true)) | ||
^ | ||
one error found |
4 changes: 2 additions & 2 deletions
4
test/files/neg/macro-divergence-controlled/Impls_Macros_1.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
null | ||
C2 |
25 changes: 25 additions & 0 deletions
25
test/files/run/macro-whitebox-dynamic-materialization/Macros_1.scala
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,25 @@ | ||
import scala.reflect.macros.WhiteboxContext | ||
import scala.language.experimental.macros | ||
|
||
trait Foo[T] | ||
|
||
class C1(val x: Int) | ||
class C2(val x: String) | ||
|
||
trait LowPriority { | ||
implicit def lessSpecific[T]: Foo[T] = null | ||
} | ||
|
||
object Foo extends LowPriority { | ||
implicit def moreSpecific[T]: Foo[T] = macro Macros.impl[T] | ||
} | ||
|
||
object Macros { | ||
def impl[T: c.WeakTypeTag](c: WhiteboxContext) = { | ||
import c.universe._ | ||
val tpe = weakTypeOf[T] | ||
if (tpe.members.exists(_.typeSignature =:= typeOf[Int])) | ||
c.abort(c.enclosingPosition, "I don't like classes that contain integers") | ||
q"new Foo[$tpe]{ override def toString = ${tpe.toString} }" | ||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
test/files/run/macro-whitebox-dynamic-materialization/Test_2.scala
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,4 @@ | ||
object Test extends App { | ||
println(implicitly[Foo[C1]]) | ||
println(implicitly[Foo[C2]]) | ||
} |