Skip to content

Commit e104f8e

Browse files
committed
Exclude AnyVal from set of pure base classes
User-defined value classes should be able to capture capabilities
1 parent 25104d1 commit e104f8e

File tree

3 files changed

+4
-7
lines changed

3 files changed

+4
-7
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1388,11 +1388,12 @@ class Definitions {
13881388
/** Base classes that are assumed to be pure for the purposes of capture checking.
13891389
* Every class inheriting from a pure baseclass is pure.
13901390
*/
1391-
@tu lazy val pureBaseClasses = Set(defn.AnyValClass, defn.ThrowableClass)
1391+
@tu lazy val pureBaseClasses = Set(defn.ThrowableClass)
13921392

13931393
/** Non-inheritable lasses that are assumed to be pure for the purposes of capture checking,
13941394
*/
1395-
@tu lazy val pureSimpleClasses = Set(StringClass, NothingClass, NullClass)
1395+
@tu lazy val pureSimpleClasses =
1396+
Set(StringClass, NothingClass, NullClass) ++ ScalaValueClasses()
13961397

13971398
@tu lazy val AbstractFunctionType: Array[TypeRef] = mkArityArray("scala.runtime.AbstractFunction", MaxImplementedFunctionArity, 0).asInstanceOf[Array[TypeRef]]
13981399
val AbstractFunctionClassPerRun: PerRun[Array[Symbol]] = new PerRun(AbstractFunctionType.map(_.symbol.asClass))

tests/neg-custom-args/captures/exception-definitions.check

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,6 @@
33
|^
44
|reference (caps.cap : Any) is not included in allowed capture set {} of pure base class class Throwable
55
3 | self: Err^ =>
6-
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:10:6 ----------------------------------------------
7-
10 |class Err4(c: Any^) extends AnyVal // error
8-
|^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9-
|reference (Err4.this.c : Any^) is not included in allowed capture set {} of pure base class class AnyVal
106
-- Error: tests/neg-custom-args/captures/exception-definitions.scala:7:12 ----------------------------------------------
117
7 | val x = c // error
128
| ^

tests/neg-custom-args/captures/exception-definitions.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ def test(c: Any^) =
77
val x = c // error
88
class Err3(c: Any^) extends Exception // error
99

10-
class Err4(c: Any^) extends AnyVal // error
10+
class Err4(c: Any^) extends AnyVal // was error, now ok
1111

1212

0 commit comments

Comments
 (0)