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