File tree 3 files changed +24
-5
lines changed
src/dotty/tools/dotc/transform
3 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,9 @@ import SymUtils._
32
32
* in [[ElimErasedValueType ]].
33
33
* This is different from the implementation of value classes in Scala 2
34
34
* (see SIP-15) which uses `asInstanceOf` which does not typecheck.
35
+ *
36
+ * Finally, if the constructor of a value class is private pr protected
37
+ * it is widened to public.
35
38
*/
36
39
class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with FullParameterization { thisTransformer =>
37
40
@@ -96,11 +99,18 @@ class ExtensionMethods extends MiniPhaseTransform with DenotTransformer with Ful
96
99
case _ =>
97
100
moduleClassSym
98
101
}
99
- case ref : SymDenotation
100
- if isMethodWithExtension(ref) && ref.hasAnnotation(defn.TailrecAnnot ) =>
101
- val ref1 = ref.copySymDenotation()
102
- ref1.removeAnnotation(defn.TailrecAnnot )
103
- ref1
102
+ case ref : SymDenotation =>
103
+ if (isMethodWithExtension(ref) && ref.hasAnnotation(defn.TailrecAnnot )) {
104
+ val ref1 = ref.copySymDenotation()
105
+ ref1.removeAnnotation(defn.TailrecAnnot )
106
+ ref1
107
+ }
108
+ else if (ref.isConstructor && isDerivedValueClass(ref.owner) && ref.is(AccessFlags )) {
109
+ val ref1 = ref.copySymDenotation()
110
+ ref1.resetFlag(AccessFlags )
111
+ ref1
112
+ }
113
+ else ref
104
114
case _ =>
105
115
ref
106
116
}
Original file line number Diff line number Diff line change
1
+ final class PosZInt private (val value : Int ) extends AnyVal
2
+
3
+ object PosZInt {
4
+ def from (value : Int ): Option [PosZInt ] =
5
+ if (value >= 0 ) Some (new PosZInt (value)) else None
6
+ }
Original file line number Diff line number Diff line change
1
+ object Test {
2
+ scala.util.Try (PosZInt .from(1 ).get)
3
+ }
You can’t perform that action at this time.
0 commit comments