diff options
author | Antoine Gourlay <antoine@gourlay.fr> | 2014-08-18 10:18:46 +0200 |
---|---|---|
committer | Antoine Gourlay <antoine@gourlay.fr> | 2014-09-09 11:53:16 +0200 |
commit | e01b461ad98a7cd6183d222ef91c674306c62ffd (patch) | |
tree | 11705a163d132611f4b7574e272408969e4b160d | |
parent | 7a6947487dc8ea551ff7489b07cc30366b39d25e (diff) | |
download | scala-e01b461ad98a7cd6183d222ef91c674306c62ffd.tar.gz scala-e01b461ad98a7cd6183d222ef91c674306c62ffd.tar.bz2 scala-e01b461ad98a7cd6183d222ef91c674306c62ffd.zip |
[nomaster] SI-8764 fix return type of case class productElement under Xexperimental
Under Xexperimental, productElement now returns the lub instead
of the weak lub of case class parameter types (numeric widening
shouldn't magically happen *inside* productElement).
This was removed from 2.12.x in 6317ae2.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala | 2 | ||||
-rw-r--r-- | test/files/neg/t8764.check | 6 | ||||
-rw-r--r-- | test/files/neg/t8764.flags | 1 | ||||
-rw-r--r-- | test/files/neg/t8764.scala | 9 | ||||
-rw-r--r-- | test/files/run/t8764.check | 5 | ||||
-rw-r--r-- | test/files/run/t8764.flags | 1 | ||||
-rw-r--r-- | test/files/run/t8764.scala | 16 |
7 files changed, 39 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala index d0237fb468..bedca88974 100644 --- a/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala +++ b/src/compiler/scala/tools/nsc/typechecker/SyntheticMethods.scala @@ -95,7 +95,7 @@ trait SyntheticMethods extends ast.TreeDSL { // which they shouldn't. val accessorLub = ( if (settings.Xexperimental) { - global.weakLub(accessors map (_.tpe.finalResultType)) match { + global.lub(accessors map (_.tpe.finalResultType)) match { case RefinedType(parents, decls) if !decls.isEmpty => intersectionType(parents) case tp => tp } diff --git a/test/files/neg/t8764.check b/test/files/neg/t8764.check new file mode 100644 index 0000000000..6d89ebe106 --- /dev/null +++ b/test/files/neg/t8764.check @@ -0,0 +1,6 @@ +t8764.scala:8: error: type mismatch; + found : AnyVal + required: Double + val d: Double = a.productElement(0) + ^ +one error found diff --git a/test/files/neg/t8764.flags b/test/files/neg/t8764.flags new file mode 100644 index 0000000000..48fd867160 --- /dev/null +++ b/test/files/neg/t8764.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/test/files/neg/t8764.scala b/test/files/neg/t8764.scala new file mode 100644 index 0000000000..dc5bfb0160 --- /dev/null +++ b/test/files/neg/t8764.scala @@ -0,0 +1,9 @@ +object Main { + + case class IntAndDouble(i: Int, d: Double) + + // a.productElement used to be Int => Double + // now: Int => AnyVal + val a = IntAndDouble(1, 5.0) + val d: Double = a.productElement(0) +} diff --git a/test/files/run/t8764.check b/test/files/run/t8764.check new file mode 100644 index 0000000000..6260069602 --- /dev/null +++ b/test/files/run/t8764.check @@ -0,0 +1,5 @@ +IntOnly: should return an unboxed int +Int: int +IntAndDouble: should just box and return Anyval +Double: class java.lang.Double +Int: class java.lang.Integer diff --git a/test/files/run/t8764.flags b/test/files/run/t8764.flags new file mode 100644 index 0000000000..48fd867160 --- /dev/null +++ b/test/files/run/t8764.flags @@ -0,0 +1 @@ +-Xexperimental diff --git a/test/files/run/t8764.scala b/test/files/run/t8764.scala new file mode 100644 index 0000000000..decc658f6e --- /dev/null +++ b/test/files/run/t8764.scala @@ -0,0 +1,16 @@ +object Test extends App { +case class IntOnly(i: Int, j: Int) + +println("IntOnly: should return an unboxed int") +val a = IntOnly(1, 2) +val i: Int = a.productElement(0) +println(s"Int: ${a.productElement(0).getClass}") + +case class IntAndDouble(i: Int, d: Double) + +println("IntAndDouble: should just box and return Anyval") +val b = IntAndDouble(1, 2.0) +val j: AnyVal = b.productElement(0) +println(s"Double: ${b.productElement(1).getClass}") +println(s"Int: ${b.productElement(0).getClass}") +} |