Skip to content

Commit 5bb73b1

Browse files
committed
Never generate function parents for companions of enum cases
The previous condition when we can and cannot generate a parent is quite obscure, so we should drop it altogether.
1 parent 7ccc244 commit 5bb73b1

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -599,10 +599,10 @@ object desugar {
599599
constrVparamss.length > 1 ||
600600
mods.is(Abstract) ||
601601
restrictedAccess ||
602-
isEnumCase && applyResultTpt.isEmpty) anyRef
602+
isEnumCase) anyRef
603603
else
604604
// todo: also use anyRef if constructor has a dependent method type (or rule that out)!
605-
(constrVparamss :\ (if (isEnumCase) applyResultTpt else classTypeRef)) (
605+
(constrVparamss :\ classTypeRef) (
606606
(vparams, restpe) => Function(vparams map (_.tpt), restpe))
607607
def widenedCreatorExpr =
608608
(creatorExpr /: widenDefs)((rhs, meth) => Apply(Ident(meth.name), rhs :: Nil))

tests/neg/enums.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ enum E3[-T <: Ordered[T]] {
1919

2020
enum E4 {
2121
case C
22+
case C4(x: Int)
23+
val x3: Int => E4 = C4(_)
24+
}
25+
object E4 {
26+
val x1: Int => E4 = C4 // error: found: C4, required: Int => E4
27+
val x2: Int => E4 = C4(_) // ok
2228
}
2329

2430
case class C4() extends E4 // error: cannot extend enum

tests/run/enums.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ object Test6 {
105105
case Green extends Color(3)
106106
case Red extends Color(2)
107107
case Violet extends Color(Green.x + Red.x)
108+
case RGB(xx: Int) extends Color(xx)
108109
}
109110
}
110111

0 commit comments

Comments
 (0)