File tree Expand file tree Collapse file tree 4 files changed +11
-6
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +11
-6
lines changed Original file line number Diff line number Diff line change @@ -20,13 +20,19 @@ object desugar {
20
20
/** Info of a variable in a pattern: The named tree and its type */
21
21
private type VarInfo = (NameTree , Tree )
22
22
23
- /** Names of methods that are added unconditionally to case classes */
24
- def isDesugaredCaseClassMethodName (name : Name )(implicit ctx : Context ): Boolean = name match {
23
+ /** Is `name` the name of a method that can be invalidated as a compiler-generated
24
+ * case class method that clashes with a user-defined method?
25
+ */
26
+ def isRetractableCaseClassMethodName (name : Name )(implicit ctx : Context ): Boolean = name match {
25
27
case nme.apply | nme.unapply | nme.copy => true
26
28
case DefaultGetterName (nme.copy, _) => true
27
- case _ => name.isSelectorName
29
+ case _ => false
28
30
}
29
31
32
+ /** Is `name` the name of a method that is added unconditionally to case classes? */
33
+ def isDesugaredCaseClassMethodName (name : Name )(implicit ctx : Context ): Boolean =
34
+ isRetractableCaseClassMethodName(name) || name.isSelectorName
35
+
30
36
// ----- DerivedTypeTrees -----------------------------------
31
37
32
38
class SetterParamTree extends DerivedTypeTree {
Original file line number Diff line number Diff line change @@ -780,7 +780,7 @@ class Namer { typer: Typer =>
780
780
}
781
781
val isClashingSynthetic =
782
782
denot.is(Synthetic ) &&
783
- desugar.isDesugaredCaseClassMethodName (denot.name) &&
783
+ desugar.isRetractableCaseClassMethodName (denot.name) &&
784
784
isCaseClass(denot.owner) &&
785
785
denot.owner.info.decls.lookupAll(denot.name).exists(alt =>
786
786
alt != denot.symbol && alt.info.matchesLoosely(denot.info))
Original file line number Diff line number Diff line change @@ -1415,7 +1415,7 @@ class Typer extends Namer
1415
1415
1416
1416
def typedDefDef (ddef : untpd.DefDef , sym : Symbol )(implicit ctx : Context ): Tree = track(" typedDefDef" ) {
1417
1417
if (! sym.info.exists) { // it's a discarded synthetic case class method, drop it
1418
- assert(sym.is(Synthetic ) && desugar.isDesugaredCaseClassMethodName (sym.name))
1418
+ assert(sym.is(Synthetic ) && desugar.isRetractableCaseClassMethodName (sym.name))
1419
1419
sym.owner.info.decls.openForMutations.unlink(sym)
1420
1420
return EmptyTree
1421
1421
}
Original file line number Diff line number Diff line change @@ -14,7 +14,6 @@ object ClashNoSig { // ok
14
14
}
15
15
}
16
16
case class ClashNoSig private (x : Int ) {
17
- def _1 : Int = x
18
17
def copy (y : Int ) = ClashNoSig (y)
19
18
}
20
19
You can’t perform that action at this time.
0 commit comments