Skip to content

Commit 4654cc1

Browse files
committed
add named arguments tests
1 parent f70a179 commit 4654cc1

File tree

5 files changed

+43
-1
lines changed

5 files changed

+43
-1
lines changed

compiler/test/dotty/tools/dotc/semanticdb/SemanticdbTests.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class SemanticdbTests {
6565
"-Ysemanticdb",
6666
"-d", target.toString,
6767
// "-Ydebug",
68-
// "-Xprint:extractSemanticDB",
68+
"-Xprint:extractSemanticDB",
6969
"-sourceroot", src.toString,
7070
"-usejavacp",
7171
) ++ inputFiles().map(_.toString)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
object NamedApplyBlockMethods/*<<=example.NamedApplyBlockMethods.*/ {
4+
val local/*<<=example.NamedApplyBlockMethods.local.*/ = 1
5+
def foo/*<<=example.NamedApplyBlockMethods.foo().*/(a/*<<=example.NamedApplyBlockMethods.foo().(a)*/: Int/*=>>scala.Int#*/ = 1, b/*<<=example.NamedApplyBlockMethods.foo().(b)*/: Int/*=>>scala.Int#*/ = 2, c/*<<=example.NamedApplyBlockMethods.foo().(c)*/: Int/*=>>scala.Int#*/ = 3): Int/*=>>scala.Int#*/ = a/*=>>example.NamedApplyBlockMethods.foo().(a)*/ +/*=>>scala.Int#`+`(+4).*/ b/*=>>example.NamedApplyBlockMethods.foo().(b)*/ +/*=>>scala.Int#`+`(+4).*/ c/*=>>example.NamedApplyBlockMethods.foo().(c)*/
6+
def baseCase/*<<=example.NamedApplyBlockMethods.baseCase().*/ = foo/*=>>example.NamedApplyBlockMethods.foo().*/(local/*=>>example.NamedApplyBlockMethods.local.*/, c = 3) // as named apply is desugared, it would take more work to inspect within the body of the setter
7+
def recursive/*<<=example.NamedApplyBlockMethods.recursive().*/ = foo/*=>>example.NamedApplyBlockMethods.foo().*/(local/*=>>example.NamedApplyBlockMethods.local.*/, c = foo(local, c = 3)) // as named apply is desugared, it would take more work to inspect within the body of the setter
8+
}
9+
10+
object NamedApplyBlockCaseClassConstruction/*<<=example.NamedApplyBlockCaseClassConstruction.*/ {
11+
case class Msg/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#*/(body/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#body.*/: String/*=>>scala.Predef.String#*/, head/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#head.*/: String/*=>>scala.Predef.String#*/ = "default", tail/*<<=example.NamedApplyBlockCaseClassConstruction.Msg#tail.*/: String/*=>>scala.Predef.String#*/)
12+
val bodyText/*<<=example.NamedApplyBlockCaseClassConstruction.bodyText.*/ = "body"
13+
val msg/*<<=example.NamedApplyBlockCaseClassConstruction.msg.*/ = Msg/*=>>example.NamedApplyBlockCaseClassConstruction.Msg.*/(bodyText/*=>>example.NamedApplyBlockCaseClassConstruction.bodyText.*/, tail = "tail")
14+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package example
2+
3+
object NamedApplyBlockMethods {
4+
val local = 1
5+
def foo(a: Int = 1, b: Int = 2, c: Int = 3): Int = a + b + c
6+
def baseCase = foo(local, c = 3) // as named apply is desugared, it would take more work to inspect within the body of the setter
7+
def recursive = foo(local, c = foo(local, c = 3)) // as named apply is desugared, it would take more work to inspect within the body of the setter
8+
}
9+
10+
object NamedApplyBlockCaseClassConstruction {
11+
case class Msg(body: String, head: String = "default", tail: String)
12+
val bodyText = "body"
13+
val msg = Msg(bodyText, tail = "tail")
14+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example
2+
3+
class NamedArguments/*<<=example.NamedArguments#*/ {
4+
case class User/*<<=example.NamedArguments#User#*/(name/*<<=example.NamedArguments#User#name.*/: String/*=>>scala.Predef.String#*/)
5+
User/*=>>example.NamedArguments#User.*/(name = "John")
6+
User/*=>>example.NamedArguments#User.*/.apply/*=>>example.NamedArguments#User.apply().*/(name = "John")
7+
}

tests/semanticdb/NamedArguments.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package example
2+
3+
class NamedArguments {
4+
case class User(name: String)
5+
User(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
6+
User.apply(name = "John") // as there is no API to get the symbols of method arguments, this proposes a problem for how to generate references from a NamedArg
7+
}

0 commit comments

Comments
 (0)