diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-01-28 17:01:56 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-01-28 17:01:56 +0100 |
commit | 494aee2feef50fadaf9f851eae4128e8dad81f8a (patch) | |
tree | 0c747cbb476194303e1b69b5d669b18d22dfb3ac | |
parent | ab0a83d1456877c6a38f32b1d2a4529cbaa90a45 (diff) | |
parent | 4c02b441da6c54fa47c01bff98a423dcbd46203b (diff) | |
download | dotty-494aee2feef50fadaf9f851eae4128e8dad81f8a.tar.gz dotty-494aee2feef50fadaf9f851eae4128e8dad81f8a.tar.bz2 dotty-494aee2feef50fadaf9f851eae4128e8dad81f8a.zip |
Merge pull request #1910 from dotty-staging/fix/#1908-synthetic-desugarings
Fix #1908: give synthetic default params correct flags
-rw-r--r-- | compiler/src/dotty/tools/dotc/ast/Desugar.scala | 4 | ||||
-rw-r--r-- | compiler/test/dotty/tools/dotc/ast/DesugarTests.scala | 49 |
2 files changed, 52 insertions, 1 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 211683c0a..2e471e046 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -190,7 +190,9 @@ object desugar { vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam), n), tpt = TypeTree(), rhs = vparam.rhs - ).withMods(Modifiers(mods.flags & AccessFlags, mods.privateWithin)) + ) + .withMods(Modifiers(mods.flags & AccessFlags, mods.privateWithin)) + .withFlags(Synthetic) val rest = defaultGetters(vparams :: vparamss1, n + 1) if (vparam.rhs.isEmpty) rest else defaultGetter :: rest case Nil :: vparamss1 => diff --git a/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala new file mode 100644 index 000000000..8d4d6a583 --- /dev/null +++ b/compiler/test/dotty/tools/dotc/ast/DesugarTests.scala @@ -0,0 +1,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) + } +} |