@@ -58,55 +58,6 @@ fn castToOptionalTypeError(z: i32) !void {
58
58
try expect ((b catch unreachable ).? .a == 1 );
59
59
}
60
60
61
- test "implicitly cast from int to anyerror!?T" {
62
- implicitIntLitToOptional ();
63
- comptime implicitIntLitToOptional ();
64
- }
65
- fn implicitIntLitToOptional () void {
66
- const f : ? i32 = 1 ;
67
- _ = f ;
68
- const g : anyerror ! ? i32 = 1 ;
69
- _ = g catch {};
70
- }
71
-
72
- test "return null from fn() anyerror!?&T" {
73
- const a = returnNullFromOptionalTypeErrorRef ();
74
- const b = returnNullLitFromOptionalTypeErrorRef ();
75
- try expect ((try a ) == null and (try b ) == null );
76
- }
77
- fn returnNullFromOptionalTypeErrorRef () anyerror ! ? * A {
78
- const a : ? * A = null ;
79
- return a ;
80
- }
81
- fn returnNullLitFromOptionalTypeErrorRef () anyerror ! ? * A {
82
- return null ;
83
- }
84
-
85
- test "peer type resolution: [0]u8 and []const u8" {
86
- try expect (peerTypeEmptyArrayAndSlice (true , "hi" ).len == 0 );
87
- try expect (peerTypeEmptyArrayAndSlice (false , "hi" ).len == 1 );
88
- comptime {
89
- try expect (peerTypeEmptyArrayAndSlice (true , "hi" ).len == 0 );
90
- try expect (peerTypeEmptyArrayAndSlice (false , "hi" ).len == 1 );
91
- }
92
- }
93
- fn peerTypeEmptyArrayAndSlice (a : bool , slice : []const u8 ) []const u8 {
94
- if (a ) {
95
- return &[_ ]u8 {};
96
- }
97
-
98
- return slice [0.. 1];
99
- }
100
-
101
- test "implicitly cast from [N]T to ?[]const T" {
102
- try expect (mem .eql (u8 , castToOptionalSlice ().? , "hi" ));
103
- comptime try expect (mem .eql (u8 , castToOptionalSlice ().? , "hi" ));
104
- }
105
-
106
- fn castToOptionalSlice () ? []const u8 {
107
- return "hi" ;
108
- }
109
-
110
61
test "implicitly cast from [0]T to anyerror![]T" {
111
62
try testCastZeroArrayToErrSliceMut ();
112
63
comptime try testCastZeroArrayToErrSliceMut ();
@@ -191,23 +142,6 @@ fn testPeerErrorAndArray2(x: u8) anyerror![]const u8 {
191
142
};
192
143
}
193
144
194
- test "cast u128 to f128 and back" {
195
- comptime try testCast128 ();
196
- try testCast128 ();
197
- }
198
-
199
- fn testCast128 () ! void {
200
- try expect (cast128Int (cast128Float (0x7fff0000000000000000000000000000 )) == 0x7fff0000000000000000000000000000 );
201
- }
202
-
203
- fn cast128Int (x : f128 ) u128 {
204
- return @bitCast (u128 , x );
205
- }
206
-
207
- fn cast128Float (x : u128 ) f128 {
208
- return @bitCast (f128 , x );
209
- }
210
-
211
145
test "single-item pointer of array to slice to unknown length pointer" {
212
146
try testCastPtrOfArrayToSliceAndPtr ();
213
147
comptime try testCastPtrOfArrayToSliceAndPtr ();
@@ -316,27 +250,6 @@ test "@floatCast cast down" {
316
250
}
317
251
}
318
252
319
- test "implicit cast from *[N]T to ?[*]T" {
320
- var x : ? [* ]u16 = null ;
321
- var y : [4 ]u16 = [4 ]u16 { 0 , 1 , 2 , 3 };
322
-
323
- x = & y ;
324
- try expect (std .mem .eql (u16 , x .? [0.. 4], y [0.. 4]));
325
- x .? [0 ] = 8 ;
326
- y [3 ] = 6 ;
327
- try expect (std .mem .eql (u16 , x .? [0.. 4], y [0.. 4]));
328
- }
329
-
330
- test "implicit cast from *T to ?*c_void" {
331
- var a : u8 = 1 ;
332
- incrementVoidPtrValue (& a );
333
- try std .testing .expect (a == 2 );
334
- }
335
-
336
- fn incrementVoidPtrValue (value : ? * c_void ) void {
337
- @ptrCast (* u8 , value .? ).* += 1 ;
338
- }
339
-
340
253
test "peer type resolution: unreachable, null, slice" {
341
254
const S = struct {
342
255
fn doTheTest (num : usize , word : []const u8 ) ! void {
@@ -374,11 +287,6 @@ test "peer type resolution: unreachable, error set, unreachable" {
374
287
try expect (transformed_err == error .SystemResources );
375
288
}
376
289
377
- test "implicit cast *[0]T to E![]const u8" {
378
- var x = @as (anyerror ! []const u8 , &[0 ]u8 {});
379
- try expect ((x catch unreachable ).len == 0 );
380
- }
381
-
382
290
test "peer cast *[0]T to E![]const T" {
383
291
var buffer : [5 ]u8 = "abcde" .* ;
384
292
var buf : anyerror ! []const u8 = buffer [0.. ];
@@ -395,24 +303,6 @@ test "peer cast *[0]T to []const T" {
395
303
try expect (mem .eql (u8 , "abcde" , y ));
396
304
}
397
305
398
- var global_array : [4 ]u8 = undefined ;
399
- test "cast from array reference to fn" {
400
- const f = @ptrCast (fn () callconv (.C ) void , & global_array );
401
- try expect (@ptrToInt (f ) == @ptrToInt (& global_array ));
402
- }
403
-
404
- test "*const [N]null u8 to ?[]const u8" {
405
- const S = struct {
406
- fn doTheTest () ! void {
407
- var a = "Hello" ;
408
- var b : ? []const u8 = a ;
409
- try expect (mem .eql (u8 , b .? , "Hello" ));
410
- }
411
- };
412
- try S .doTheTest ();
413
- comptime try S .doTheTest ();
414
- }
415
-
416
306
test "peer resolution of string literals" {
417
307
const S = struct {
418
308
const E = enum { a , b , c , d };
@@ -502,19 +392,6 @@ test "cast i8 fn call peers to i32 result" {
502
392
comptime try S .doTheTest ();
503
393
}
504
394
505
- test "return u8 coercing into ?u32 return type" {
506
- const S = struct {
507
- fn doTheTest () ! void {
508
- try expect (foo (123 ).? == 123 );
509
- }
510
- fn foo (arg : u8 ) ? u32 {
511
- return arg ;
512
- }
513
- };
514
- try S .doTheTest ();
515
- comptime try S .doTheTest ();
516
- }
517
-
518
395
test "peer type resolution implicit cast to return type" {
519
396
const S = struct {
520
397
fn doTheTest () ! void {
@@ -553,24 +430,6 @@ test "variable initialization uses result locations properly with regards to the
553
430
try expect (x == 1 );
554
431
}
555
432
556
- test "cast between [*c]T and ?[*:0]T on fn parameter" {
557
- const S = struct {
558
- const Handler = ? fn ([* c ]const u8 ) callconv (.C ) void ;
559
- fn addCallback (handler : Handler ) void {
560
- _ = handler ;
561
- }
562
-
563
- fn myCallback (cstr : ? [* :0 ]const u8 ) callconv (.C ) void {
564
- _ = cstr ;
565
- }
566
-
567
- fn doTheTest () void {
568
- addCallback (myCallback );
569
- }
570
- };
571
- S .doTheTest ();
572
- }
573
-
574
433
test "cast between C pointer with different but compatible types" {
575
434
const S = struct {
576
435
fn foo (arg : [* ]c_ushort ) u16 {
@@ -584,13 +443,6 @@ test "cast between C pointer with different but compatible types" {
584
443
try S .doTheTest ();
585
444
}
586
445
587
- var global_struct : struct { f0 : usize } = undefined ;
588
-
589
- test "assignment to optional pointer result loc" {
590
- var foo : struct { ptr : ? * c_void } = .{ .ptr = & global_struct };
591
- try expect (foo .ptr .? == @ptrCast (* c_void , & global_struct ));
592
- }
593
-
594
446
test "peer type resolve string lit with sentinel-terminated mutable slice" {
595
447
var array : [4 :0 ]u8 = undefined ;
596
448
array [4 ] = 0 ; // TODO remove this when #4372 is solved
@@ -649,14 +501,3 @@ test "comptime float casts" {
649
501
fn expectFloatToInt (comptime F : type , f : F , comptime I : type , i : I ) ! void {
650
502
try expect (@floatToInt (I , f ) == i );
651
503
}
652
-
653
- test "cast from ?[*]T to ??[*]T" {
654
- const a : ?? [* ]u8 = @as (? [* ]u8 , null );
655
- try expect (a != null and a .? == null );
656
- }
657
-
658
- test "cast between *[N]void and []void" {
659
- var a : [4 ]void = undefined ;
660
- var b : []void = & a ;
661
- try expect (b .len == 4 );
662
- }
0 commit comments