1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
package dotty.tools
package dotc
package ast
import core._
import Names._, Types._ , Symbols._, StdNames._, Flags._, Contexts._
import org.junit.Test
import org.junit.Assert._
class DesugarTests extends DottyTest {
import tpd._
private def validSym(sym: Symbol)(implicit ctx: Context): Unit = {
assert(
// remaining symbols must be either synthetic:
sym.is(Synthetic) ||
// or be a type argument from product:
(sym.isType && sym.is(BaseTypeArg)) ||
// or be a constructor:
sym.name == nme.CONSTRUCTOR,
s"found: $sym (${sym.flags})"
)
}
@Test def caseClassHasCorrectMembers =
checkCompile("frontend", "case class Foo(x: Int, y: String)") { (tree, context) =>
implicit val ctx = context
val ccTree = tree.find(tree => tree.symbol.name == typeName("Foo")).get
val List(_, foo) = defPath(ccTree.symbol, tree).map(_.symbol.info)
val x :: y :: rest = foo.decls.toList
// Make sure we extracted the correct values from foo:
assert(x.name == termName("x"))
assert(y.name == termName("y"))
rest.foreach(validSym)
}
@Test def caseClassCompanionHasCorrectMembers =
checkCompile("frontend", "case class Foo(x: Int, y: String)") { (tree, context) =>
implicit val ctx = context
val ccTree = tree.find(tree => tree.symbol.name == termName("Foo")).get
val List(_, foo) = defPath(ccTree.symbol, tree).map(_.symbol.info)
foo.decls.foreach(validSym)
}
}
|