Skip to content

Commit 6317ae2

Browse files
committed
SI-8764 remove Xexperimental special Product members for case classes
`productElement` and `productIterator` return types under Xexperimental use the weak lub of the case class's parameters instead of just Any. This isn't really useful, nor tested and it is broken (SI-8764) anyway. The special casing of `productElement` and `productIterator` was introduced with `ProductN` support in case classes (e412524), but was not removed when `ProductN` support went away (70996f8, d7f498a, b7395e9, 317a105).
1 parent 5fac01e commit 6317ae2

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,6 @@ trait SyntheticMethods extends ast.TreeDSL {
8484

8585
def accessors = clazz.caseFieldAccessors
8686
val arity = accessors.size
87-
// If this is ProductN[T1, T2, ...], accessorLub is the lub of T1, T2, ..., .
88-
// !!! Hidden behind -Xexperimental due to bummer type inference bugs.
89-
// Refining from Iterator[Any] leads to types like
90-
//
91-
// Option[Int] { def productIterator: Iterator[String] }
92-
//
93-
// appearing legitimately, but this breaks invariant places
94-
// like Tags and Arrays which are not robust and infer things
95-
// which they shouldn't.
96-
val accessorLub = (
97-
if (settings.Xexperimental) {
98-
global.weakLub(accessors map (_.tpe.finalResultType)) match {
99-
case RefinedType(parents, decls) if !decls.isEmpty => intersectionType(parents)
100-
case tp => tp
101-
}
102-
}
103-
else AnyTpe
104-
)
10587

10688
def forwardToRuntime(method: Symbol): Tree =
10789
forwardMethod(method, getMember(ScalaRunTimeModule, (method.name prepend "_")))(mkThis :: _)
@@ -122,8 +104,8 @@ trait SyntheticMethods extends ast.TreeDSL {
122104
}
123105
}
124106
def productIteratorMethod = {
125-
createMethod(nme.productIterator, iteratorOfType(accessorLub))(_ =>
126-
gen.mkMethodCall(ScalaRunTimeModule, nme.typedProductIterator, List(accessorLub), List(mkThis))
107+
createMethod(nme.productIterator, iteratorOfType(AnyTpe))(_ =>
108+
gen.mkMethodCall(ScalaRunTimeModule, nme.typedProductIterator, List(AnyTpe), List(mkThis))
127109
)
128110
}
129111

@@ -243,7 +225,7 @@ trait SyntheticMethods extends ast.TreeDSL {
243225
List(
244226
Product_productPrefix -> (() => constantNullary(nme.productPrefix, clazz.name.decode)),
245227
Product_productArity -> (() => constantNullary(nme.productArity, arity)),
246-
Product_productElement -> (() => perElementMethod(nme.productElement, accessorLub)(mkThisSelect)),
228+
Product_productElement -> (() => perElementMethod(nme.productElement, AnyTpe)(mkThisSelect)),
247229
Product_iterator -> (() => productIteratorMethod),
248230
Product_canEqual -> (() => canEqualMethod)
249231
// This is disabled pending a reimplementation which doesn't add any

0 commit comments

Comments
 (0)