File tree 5 files changed +22
-7
lines changed 5 files changed +22
-7
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,7 @@ import Constants._
12
12
import TreeTransforms ._
13
13
import Flags ._
14
14
import Decorators ._
15
+ import ValueClasses ._
15
16
16
17
/** Performs the following rewritings for fields of a class:
17
18
*
@@ -34,7 +35,7 @@ import Decorators._
34
35
*
35
36
* Omitted from the rewritings are
36
37
*
37
- * - private[this] fields in non-trait classes
38
+ * - private[this] fields in classes (excluding traits, value classes)
38
39
* - fields generated for static modules (TODO: needed?)
39
40
* - parameters, static fields, and fields coming from Java
40
41
*
@@ -53,7 +54,7 @@ class Getters extends MiniPhaseTransform with SymTransformer { thisTransform =>
53
54
override def transformSym (d : SymDenotation )(implicit ctx : Context ): SymDenotation = {
54
55
def noGetterNeeded =
55
56
d.is(NoGetterNeeded ) ||
56
- d.initial.asInstanceOf [SymDenotation ].is(PrivateLocal ) && ! d.owner.is(Trait ) && ! d.is(Flags .Lazy ) ||
57
+ d.initial.asInstanceOf [SymDenotation ].is(PrivateLocal ) && ! d.owner.is(Trait ) && ! isDerivedValueClass(d.owner) && ! d.is(Flags .Lazy ) ||
57
58
d.is(Module ) && d.isStatic ||
58
59
d.isSelfSym
59
60
if (d.isTerm && (d.is(Lazy ) || d.owner.isClass) && d.info.isValueType && ! noGetterNeeded) {
Original file line number Diff line number Diff line change @@ -715,8 +715,6 @@ object RefChecks {
715
715
case List (param) =>
716
716
if (param.is(Mutable ))
717
717
ctx.error(" value class parameter must not be a var" , param.pos)
718
- if (param.is(PrivateLocal ))
719
- ctx.error(" value class parameter must not be private[this]" , param.pos)
720
718
case _ =>
721
719
ctx.error(" value class needs to have exactly one val parameter" , clazz.pos)
722
720
}
Original file line number Diff line number Diff line change @@ -189,7 +189,7 @@ class tests extends CompilerTest {
189
189
@ Test def neg_validateRefchecks = compileFile(negDir, " validate-refchecks" , xerrors = 2 )
190
190
@ Test def neg_skolemize = compileFile(negDir, " skolemize" , xerrors = 2 )
191
191
@ Test def neg_nested_bounds = compileFile(negDir, " nested_bounds" , xerrors = 1 )
192
- @ Test def neg_valueClasses = compileFile(negDir, " valueClasses" , xerrors = 4 )
192
+ @ Test def neg_valueClasses = compileFile(negDir, " valueClasses" , xerrors = 2 )
193
193
194
194
@ Test def run_all = runFiles(runDir)
195
195
Original file line number Diff line number Diff line change @@ -6,5 +6,3 @@ class B1 {
6
6
class B2 (x : Int ) extends AnyVal // error: value class may not be a local class
7
7
}
8
8
}
9
- class C (private [this ] val u : Int ) extends AnyVal // error: value class parameter must not be private[this]
10
- class D (u : Int ) extends AnyVal // error: value class parameter must not be private[this]
Original file line number Diff line number Diff line change
1
+ package privatethisparam
2
+
3
+ class Meter [T ](x : T ) extends AnyVal {
4
+ def zero : T = x
5
+ }
6
+
7
+ class Meter2 (private [this ] val x : Int ) extends AnyVal {
8
+ def foo = x
9
+ }
10
+
11
+ object Test {
12
+ def bar = new Meter2 (42 )
13
+ def useZero = new Meter (5 ).zero
14
+ def test : Unit = {
15
+ val m1 = new Meter (1 )
16
+ m1.zero
17
+ }
18
+ }
You can’t perform that action at this time.
0 commit comments