Skip to content

Commit 494aee2

Browse files
authored
Merge pull request #1910 from dotty-staging/fix/#1908-synthetic-desugarings
Fix #1908: give synthetic default params correct flags
2 parents ab0a83d + 4c02b44 commit 494aee2

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,9 @@ object desugar {
190190
vparamss = takeUpTo(normalizedVparamss.nestedMap(toDefParam), n),
191191
tpt = TypeTree(),
192192
rhs = vparam.rhs
193-
).withMods(Modifiers(mods.flags & AccessFlags, mods.privateWithin))
193+
)
194+
.withMods(Modifiers(mods.flags & AccessFlags, mods.privateWithin))
195+
.withFlags(Synthetic)
194196
val rest = defaultGetters(vparams :: vparamss1, n + 1)
195197
if (vparam.rhs.isEmpty) rest else defaultGetter :: rest
196198
case Nil :: vparamss1 =>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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

Comments
 (0)