-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow top-level ~ in and non static inline method: * Class methods (including inner and anonymous classes) * Methods in def/val/var
- Loading branch information
1 parent
2f85824
commit e11b714
Showing
12 changed files
with
112 additions
and
6 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
6 changes: 3 additions & 3 deletions
6
tests/neg/quote-non-static-macro.scala → tests/pos/quote-non-static-macro.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
1.0 | ||
1.5 | ||
2.25 | ||
7.59375 | ||
1.0 | ||
1.5 | ||
2.25 | ||
7.59375 |
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,20 @@ | ||
|
||
class Num2(x: Double) { | ||
inline def power(inline n: Long) = ~PowerMacro.powerCode('(x), n) | ||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val n = new Num(1.5) | ||
println(n.power(0)) | ||
println(n.power(1)) | ||
println(n.power(2)) | ||
println(n.power(5)) | ||
|
||
val n2 = new Num2(1.5) | ||
println(n.power(0)) | ||
println(n.power(1)) | ||
println(n.power(2)) | ||
println(n.power(5)) | ||
} | ||
} |
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,12 @@ | ||
import scala.quoted._ | ||
|
||
object PowerMacro { | ||
def powerCode(x: Expr[Double], n: Long): Expr[Double] = | ||
if (n == 0) '(1.0) | ||
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode('(y), n / 2) } | ||
else '{ ~x * ~powerCode(x, n - 1) } | ||
} | ||
|
||
class Num(x: Double) { | ||
inline def power(inline n: Long) = ~PowerMacro.powerCode('(x), n) | ||
} |
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 @@ | ||
1.0 | ||
1.5 | ||
2.25 | ||
7.59375 |
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,18 @@ | ||
|
||
|
||
class Nums { | ||
class Num(x: Double) { | ||
inline def power(inline n: Long) = ~PowerMacro.powerCode('(x), n) | ||
} | ||
} | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
val nums = new Nums | ||
val n = new nums.Num(1.5) | ||
println(n.power(0)) | ||
println(n.power(1)) | ||
println(n.power(2)) | ||
println(n.power(5)) | ||
} | ||
} |
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,8 @@ | ||
import scala.quoted._ | ||
|
||
object PowerMacro { | ||
def powerCode(x: Expr[Double], n: Long): Expr[Double] = | ||
if (n == 0) '(1.0) | ||
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode('(y), n / 2) } | ||
else '{ ~x * ~powerCode(x, n - 1) } | ||
} |
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,8 @@ | ||
1.0 | ||
1.5 | ||
2.25 | ||
7.59375 | ||
1.0 | ||
1.5 | ||
2.25 | ||
7.59375 |
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,22 @@ | ||
|
||
object Test { | ||
def main(args: Array[String]): Unit = { | ||
class Num(x: Double) { | ||
inline def power(inline n: Long) = ~PowerMacro.powerCode('(x), n) | ||
} | ||
val n = new Num(1.5) | ||
println(n.power(0)) | ||
println(n.power(1)) | ||
println(n.power(2)) | ||
println(n.power(5)) | ||
|
||
inline def power(x: Double, inline n: Long) = ~PowerMacro.powerCode('(x), n) | ||
|
||
val x: Double = 1.5 | ||
|
||
println(power(x, 0)) | ||
println(power(x, 1)) | ||
println(power(x, 2)) | ||
println(power(x, 5)) | ||
} | ||
} |
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,8 @@ | ||
import scala.quoted._ | ||
|
||
object PowerMacro { | ||
def powerCode(x: Expr[Double], n: Long): Expr[Double] = | ||
if (n == 0) '(1.0) | ||
else if (n % 2 == 0) '{ val y = ~x * ~x; ~powerCode('(y), n / 2) } | ||
else '{ ~x * ~powerCode(x, n - 1) } | ||
} |