File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change
1
+ // Run with -explaintypes to see information about shadowing failures
2
+ import scala .reflect .{ClassTag , classTag }
3
+
4
+ object Test extends dotty.runtime.LegacyApp {
5
+ ObjectArrayClone ;
6
+ PolymorphicArrayClone ;
7
+ }
8
+
9
+ object ObjectArrayClone {
10
+ val it : Array [String ] = Array (" 1" , " 0" );
11
+ val cloned = it.clone();
12
+ assert(cloned.sameElements(it));
13
+ cloned(0 ) = " 0" ;
14
+ assert(it(0 ) == " 1" )
15
+ }
16
+
17
+ object PolymorphicArrayClone {
18
+ def testIt [T ](it : Array [T ], one : T , zero : T ) = {
19
+ val cloned = it.clone();
20
+ assert(cloned.sameElements(it));
21
+ cloned(0 ) = zero;
22
+ assert(it(0 ) == one)
23
+ }
24
+
25
+ testIt(Array (" one" , " two" ), " one" , " two" );
26
+
27
+ class Mangler [T : ClassTag ](ts : T * ){
28
+ // this will always be a BoxedAnyArray even after we've unboxed its contents.
29
+ val it = ts.toArray[T ];
30
+ }
31
+
32
+ val mangled = new Mangler [Int ](0 , 1 );
33
+
34
+ val y : Array [Int ] = mangled.it; // make sure it's unboxed
35
+
36
+ testIt(mangled.it, 0 , 1 );
37
+ }
38
+
You can’t perform that action at this time.
0 commit comments