Skip to content

Commit ad3cf75

Browse files
committed
Added bytecode tests and fixed module defn
1 parent 71e9ecd commit ad3cf75

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ class Definitions {
575575

576576
lazy val StringContextType: TypeRef = ctx.requiredClassRef("scala.StringContext")
577577
def StringContextClass(implicit ctx: Context) = StringContextType.symbol.asClass
578-
def StringContextModule(implicit ctx: Context) = StringContextClass.companionClass
578+
def StringContextModule(implicit ctx: Context) = StringContextClass.companionModule
579579

580580
lazy val PartialFunctionType: TypeRef = ctx.requiredClassRef("scala.PartialFunction")
581581
def PartialFunctionClass(implicit ctx: Context) = PartialFunctionType.symbol.asClass
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
package dotty.tools.backend.jvm
2+
3+
import org.junit.Assert._
4+
import org.junit.Test
5+
6+
class StringInterpolatorOptTest extends DottyBytecodeTest {
7+
import ASMConverters._
8+
9+
@Test def testRawInterpolator = {
10+
val source =
11+
"""
12+
|class Foo {
13+
| val one = 1
14+
| val two = "two"
15+
| val three = 3.0
16+
|
17+
| def meth1: String = raw"$one plus $two$three\n"
18+
| def meth2: String = "" + one + " plus " + two + three + "\\n"
19+
|}
20+
""".stripMargin
21+
22+
checkBCode(source) { dir =>
23+
val clsIn = dir.lookupName("Foo.class", directory = false).input
24+
val clsNode = loadClassNode(clsIn)
25+
val meth1 = getMethod(clsNode, "meth1")
26+
val meth2 = getMethod(clsNode, "meth2")
27+
28+
val instructions1 = instructionsFromMethod(meth1)
29+
val instructions2 = instructionsFromMethod(meth2)
30+
31+
assert(instructions1 == instructions2,
32+
"the `` string interpolator incorrectly converts to string concatenation\n" +
33+
diffInstructions(instructions1, instructions2))
34+
}
35+
}
36+
37+
@Test def testSInterpolator = {
38+
val source =
39+
"""
40+
|class Foo {
41+
| val one = 1
42+
| val two = "two"
43+
| val three = 3.0
44+
|
45+
| def meth1: String = s"$one plus $two$three\n"
46+
| def meth2: String = "" + one + " plus " + two + three + "\n"
47+
|}
48+
""".stripMargin
49+
50+
checkBCode(source) { dir =>
51+
val clsIn = dir.lookupName("Foo.class", directory = false).input
52+
val clsNode = loadClassNode(clsIn)
53+
val meth1 = getMethod(clsNode, "meth1")
54+
val meth2 = getMethod(clsNode, "meth2")
55+
56+
val instructions1 = instructionsFromMethod(meth1)
57+
val instructions2 = instructionsFromMethod(meth2)
58+
59+
assert(instructions1 == instructions2,
60+
"the `s` string interpolator incorrectly converts to string concatenation\n" +
61+
diffInstructions(instructions1, instructions2))
62+
}
63+
}
64+
}

0 commit comments

Comments
 (0)